Class: Coinbase::Transaction
- Inherits:
-
Object
- Object
- Coinbase::Transaction
- Defined in:
- lib/coinbase/transaction.rb
Overview
A representation of an onchain Transaction. Transactions should be constructed via higher level abstractions like Trade or Transfer.
Defined Under Namespace
Modules: Status
Instance Method Summary collapse
-
#from_address_id ⇒ String
Returns the from address for the Transaction.
-
#initialize(model) ⇒ Transaction
constructor
Returns a new Transaction object.
-
#inspect ⇒ String
Same as to_s.
-
#raw ⇒ Eth::Tx::Eip1559
Returns the underlying raw transaction.
-
#sign(key) ⇒ String
Signs the Transaction with the provided key and returns the hex signing payload.
-
#signed? ⇒ Boolean
Returns whether the Transaction has been signed.
-
#signed_payload ⇒ String
Returns the Signed Payload of the Transaction.
-
#status ⇒ Symbol
Returns the status of the Transaction.
-
#terminal_state? ⇒ Boolean
Returns whether the Transaction is in a terminal state.
-
#to_s ⇒ String
Returns a String representation of the Transaction.
-
#transaction_hash ⇒ String
Returns the Transaction Hash of the Transaction.
-
#transaction_link ⇒ String
Returns the link to the transaction on the blockchain explorer.
-
#unsigned_payload ⇒ String
Returns the Unsigned Payload of the Transaction.
Constructor Details
#initialize(model) ⇒ Transaction
Returns a new Transaction object. Do not use this method directly.
34 35 36 37 38 |
# File 'lib/coinbase/transaction.rb', line 34 def initialize(model) raise unless model.is_a?(Coinbase::Client::Transaction) @model = model end |
Instance Method Details
#from_address_id ⇒ String
Returns the from address for the Transaction.
66 67 68 |
# File 'lib/coinbase/transaction.rb', line 66 def from_address_id @model.from_address_id end |
#inspect ⇒ String
Same as to_s.
127 128 129 |
# File 'lib/coinbase/transaction.rb', line 127 def inspect to_s end |
#raw ⇒ Eth::Tx::Eip1559
Returns the underlying raw transaction.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/coinbase/transaction.rb', line 84 def raw return @raw unless @raw.nil? raw_payload = [unsigned_payload].pack('H*') parsed_payload = JSON.parse(raw_payload) params = { chain_id: parsed_payload['chainId'].to_i(16), nonce: parsed_payload['nonce'].to_i(16), priority_fee: parsed_payload['maxPriorityFeePerGas'].to_i(16), max_gas_fee: parsed_payload['maxFeePerGas'].to_i(16), gas_limit: parsed_payload['gas'].to_i(16), # TODO: Handle multiple currencies. from: Eth::Address.new(from_address_id), to: Eth::Address.new(parsed_payload['to']), value: parsed_payload['value'].to_i(16), data: parsed_payload['input'] || '' } @raw = Eth::Tx::Eip1559.new(Eth::Tx.validate_eip1559_params(params)) end |
#sign(key) ⇒ String
Signs the Transaction with the provided key and returns the hex signing payload.
107 108 109 110 111 |
# File 'lib/coinbase/transaction.rb', line 107 def sign(key) raw.sign(key) raw.hex end |
#signed? ⇒ Boolean
Returns whether the Transaction has been signed.
115 116 117 |
# File 'lib/coinbase/transaction.rb', line 115 def signed? Eth::Tx.signed?(raw) end |
#signed_payload ⇒ String
Returns the Signed Payload of the Transaction.
48 49 50 |
# File 'lib/coinbase/transaction.rb', line 48 def signed_payload @model.signed_payload end |
#status ⇒ Symbol
Returns the status of the Transaction.
60 61 62 |
# File 'lib/coinbase/transaction.rb', line 60 def status @model.status end |
#terminal_state? ⇒ Boolean
Returns whether the Transaction is in a terminal state.
72 73 74 |
# File 'lib/coinbase/transaction.rb', line 72 def terminal_state? Status::TERMINAL_STATES.include?(status) end |
#to_s ⇒ String
Returns a String representation of the Transaction.
121 122 123 |
# File 'lib/coinbase/transaction.rb', line 121 def to_s "Coinbase::Transaction{transaction_hash: '#{transaction_hash}', status: '#{status}'}" end |
#transaction_hash ⇒ String
Returns the Transaction Hash of the Transaction.
54 55 56 |
# File 'lib/coinbase/transaction.rb', line 54 def transaction_hash @model.transaction_hash end |
#transaction_link ⇒ String
Returns the link to the transaction on the blockchain explorer.
78 79 80 |
# File 'lib/coinbase/transaction.rb', line 78 def transaction_link @model.transaction_link end |
#unsigned_payload ⇒ String
Returns the Unsigned Payload of the Transaction.
42 43 44 |
# File 'lib/coinbase/transaction.rb', line 42 def unsigned_payload @model.unsigned_payload end |