Sha256: b374d65c1304cd9d3383427b067dab047ba9cfad393ebf1041540d2e9169c543

Contents?: true

Size: 1.25 KB

Versions: 29

Compression:

Stored size: 1.25 KB

Contents

#!/usr/bin/env ruby

# This is an example of using the raw xdr objects to post a transaction
# notice that we must manually hash/sign the structures and we must manually
# fill out all the fields.
#
# Look at mid_level_transaction_post.rb to see a friendlier form

require 'rbnacl'
require 'stellar-base'
require 'faraday'
require 'digest/sha2'

master      = RbNaCl::SigningKey.new("allmylifemyhearthasbeensearching")
destination = RbNaCl::SigningKey.new("allmylifemyhearthasbeensearching")

tx            = Stellar::Transaction.new
tx.account    = master.verify_key.to_bytes
tx.fee        = 1000
tx.seq_num    = 1

payment = Stellar::PaymentOp.new
payment.destination = destination.verify_key.to_bytes
payment.asset = Stellar::Asset.new(:native)
payment.amount = 200 * Stellar::ONE

op = Stellar::Operation.new
op.body = Stellar::Operation::Body.new(:payment, payment)

tx.operations = [op]

raw       = tx.to_xdr
tx_hash   = Digest::SHA256.digest raw
signature = master.sign(tx_hash)

env = Stellar::TransactionEnvelope.new
env.tx = tx
env.signatures = [Stellar::DecoratedSignature.new({
  hint:master.verify_key.to_bytes[0...4],
  signature:signature
})]

env_hex = env.to_xdr.unpack("H*").first

result = Faraday.get('http://localhost:39132/tx', blob: env_hex)
puts result.body

Version data entries

29 entries across 29 versions & 3 rubygems

Version Path
stellar-base-0.22.0 examples/low_level_transaction_post.rb
stellar-base-0.21.0 examples/low_level_transaction_post.rb
stellar-base-0.20.0 examples/low_level_transaction_post.rb
stellar-base-0.19.0 examples/low_level_transaction_post.rb
stellar-base-0.18.0 examples/low_level_transaction_post.rb
stellar-base-0.17.0 examples/low_level_transaction_post.rb
stellar-base-0.16.0 examples/low_level_transaction_post.rb
stellar-base-0.15.0 examples/low_level_transaction_post.rb
stellar-base-0.14.0 examples/low_level_transaction_post.rb
stellar-base-0.13.0 examples/low_level_transaction_post.rb
stellar-base-0.12.0 examples/low_level_transaction_post.rb
stellar-base-0.11.0 examples/low_level_transaction_post.rb
auction-ruby-base-0.1.1 examples/low_level_transaction_post.rb
stellar-base-0.10.0 examples/low_level_transaction_post.rb
stellar-base-0.9.0 examples/low_level_transaction_post.rb
stellar-base-0.8.0 examples/low_level_transaction_post.rb
stellar-base-0.7.0 examples/low_level_transaction_post.rb
stellar-base-0.6.1 examples/low_level_transaction_post.rb
stellar-base-0.6.0 examples/low_level_transaction_post.rb
stellar-base-0.5.0 examples/low_level_transaction_post.rb