Class: Coinbase::SponsoredSend

Inherits:
Object
  • Object
show all
Defined in:
lib/coinbase/sponsored_send.rb

Overview

A representation of an onchain Sponsored Send. Sponsored Sends should be constructed via higher level abstractions like Transfer.

Defined Under Namespace

Modules: Status

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ SponsoredSend

Returns a new SponsoredSend object. Do not use this method directly.



36
37
38
39
40
# File 'lib/coinbase/sponsored_send.rb', line 36

def initialize(model)
  raise unless model.is_a?(Coinbase::Client::SponsoredSend)

  @model = model
end

Instance Method Details

#inspectString

Same as to_s.



106
107
108
# File 'lib/coinbase/sponsored_send.rb', line 106

def inspect
  to_s
end

#sign(key) ⇒ String

Signs the Transaction with the provided key and returns the hex signing payload.



56
57
58
59
60
61
# File 'lib/coinbase/sponsored_send.rb', line 56

def sign(key)
  raise unless key.is_a?(Eth::Key)
  raise Coinbase::AlreadySignedError if signed?

  @signature = Eth::Util.prefix_hex(key.sign(Eth::Util.hex_to_bin(typed_data_hash)))
end

#signatureObject

Returns the signature of the typed data.



50
51
52
# File 'lib/coinbase/sponsored_send.rb', line 50

def signature
  @signature ||= @model.signature
end

#signed?Boolean

Returns whether the Transaction has been signed.



65
66
67
# File 'lib/coinbase/sponsored_send.rb', line 65

def signed?
  !signature.nil?
end

#statusSymbol

Returns the status of the Transaction.



71
72
73
# File 'lib/coinbase/sponsored_send.rb', line 71

def status
  @model.status
end

#terminal_state?Boolean

Returns whether the Sponsored Send is in a terminal state.



77
78
79
# File 'lib/coinbase/sponsored_send.rb', line 77

def terminal_state?
  Status::TERMINAL_STATES.include?(status)
end

#to_sString

Returns a String representation of the SponsoredSend.



95
96
97
98
99
100
101
102
# File 'lib/coinbase/sponsored_send.rb', line 95

def to_s
  Coinbase.pretty_print_object(
    self.class,
    status: status,
    transaction_hash: transaction_hash,
    transaction_link: transaction_link
  )
end

#transaction_hashString

Returns the Transaction Hash of the Transaction.



83
84
85
# File 'lib/coinbase/sponsored_send.rb', line 83

def transaction_hash
  @model.transaction_hash
end

Returns the link to the transaction on the blockchain explorer.



89
90
91
# File 'lib/coinbase/sponsored_send.rb', line 89

def transaction_link
  @model.transaction_link
end

#typed_data_hashString

Returns the Keccak256 hash of the typed data. This payload must be signed by the sender to be used as an approval in the EIP-3009 transaction.



45
46
47
# File 'lib/coinbase/sponsored_send.rb', line 45

def typed_data_hash
  @model.typed_data_hash
end