Class: DbchainClient::Transaction
- Inherits:
-
Object
- Object
- DbchainClient::Transaction
- Defined in:
- lib/dbchain_client/transaction.rb
Instance Method Summary collapse
-
#initialize(base_url, chain_id, private_key_hex) ⇒ Transaction
constructor
A new instance of Transaction.
- #sign_and_broadcast(messages, gas: '99999999', memo: '') ⇒ Object
Constructor Details
#initialize(base_url, chain_id, private_key_hex) ⇒ Transaction
Returns a new instance of Transaction.
8 9 10 11 12 13 |
# File 'lib/dbchain_client/transaction.rb', line 8 def initialize(base_url, chain_id, private_key_hex) @rest_lib = DbchainClient::RestLib.new(base_url) @chain_id = chain_id @private_key = PrivateKey.new(private_key_hex) @from_address = @private_key.public_key.address end |
Instance Method Details
#sign_and_broadcast(messages, gas: '99999999', memo: '') ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dbchain_client/transaction.rb', line 15 def sign_and_broadcast(, gas: '99999999', memo: '') tx = { fee: { amount: [], gas: gas }, memo: memo, msg: } = (tx, ) signature = @private_key.sign() signed_tx = { signature: Base64.strict_encode64(signature.compact), pub_key: { type: 'tendermint/PubKeySecp256k1', value: Base64.strict_encode64([@private_key.public_key.public_key_hex].pack("H*")) } } tx[:signatures] = [signed_tx] broadcastBody = { tx: tx, mode: 'async' }.to_json response = rest_post("/txs", broadcastBody) response#.data.txhash end |