Class: Coinbase::PayloadSignature

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

Overview

A representation of a Payload Signature.

Defined Under Namespace

Modules: Status

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ PayloadSignature

Returns a new PayloadSignature object. Do not use this method directly. Instead use Coinbase::PayloadSignature.create.

Parameters:



75
76
77
78
79
# File 'lib/coinbase/payload_signature.rb', line 75

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

  @model = model
end

Class Method Details

.create(wallet_id:, address_id:, unsigned_payload:, signature: nil) ⇒ PayloadSignature

Creates a new PayloadSignature object.

Parameters:

  • wallet_id (String)

    The Wallet ID associated with the signing Address

  • address_id (String)

    The Address ID of the signing Address

  • unsigned_payload (String)

    The hex-encoded Unsigned Payload

  • signature (String) (defaults to: nil)

    (Optional) The Signature if the Wallet is not using an MPC Server-Signer

Returns:

Raises:

  • (Coinbase::ApiError)

    If the request to create the Payload Signature fails



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/coinbase/payload_signature.rb', line 32

def create(wallet_id:, address_id:, unsigned_payload:, signature: nil)
  create_payload_signature_request = {
    unsigned_payload: unsigned_payload,
    signature: signature
  }.compact

  model = Coinbase.call_api do
    addresses_api.create_payload_signature(
      wallet_id,
      address_id,
      create_payload_signature_request: create_payload_signature_request
    )
  end

  new(model)
end

.list(wallet_id:, address_id:) ⇒ Enumerable<Coinbase::PayloadSignature>

Enumerates the payload signatures for a given address belonging to a wallet. The result is an enumerator that lazily fetches from the server, and can be iterated over, converted an array, etc…

Returns:



53
54
55
56
57
58
59
# File 'lib/coinbase/payload_signature.rb', line 53

def list(wallet_id:, address_id:)
  Coinbase::Pagination.enumerate(
    ->(page) { fetch_page(wallet_id, address_id, page) }
  ) do |payload_signature|
    new(payload_signature)
  end
end

Instance Method Details

#address_idString

Returns the Address ID of the Payload Signature.

Returns:

  • (String)

    The Address ID



95
96
97
# File 'lib/coinbase/payload_signature.rb', line 95

def address_id
  @model.address_id
end

#idString

Returns the Payload Signature ID.

Returns:

  • (String)

    The Payload Signature ID



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

def id
  @model.payload_signature_id
end

#inspectString

Same as to_s.

Returns:

  • (String)

    a String representation of the PayloadSignature



171
172
173
# File 'lib/coinbase/payload_signature.rb', line 171

def inspect
  to_s
end

#reloadPayloadSignature

# Reload reloads the Payload Signature model with the latest version from the server side.

Returns:

  • (PayloadSignature)

    The most recent version of Payload Signature from the server



125
126
127
128
129
130
131
# File 'lib/coinbase/payload_signature.rb', line 125

def reload
  @model = Coinbase.call_api do
    addresses_api.get_payload_signature(wallet_id, address_id, id)
  end

  self
end

#signatureString

Returns the Signature of the Payload Signature.

Returns:

  • (String)

    The Signature



107
108
109
# File 'lib/coinbase/payload_signature.rb', line 107

def signature
  @model.signature
end

#statusSymbol

Returns the status of the Payload Signature.

Returns:

  • (Symbol)

    The status



113
114
115
# File 'lib/coinbase/payload_signature.rb', line 113

def status
  @model.status
end

#terminal_state?Boolean

Returns whether the Payload Signature is in a terminal state.

Returns:

  • (Boolean)

    Whether the Payload Signature is in a terminal state



119
120
121
# File 'lib/coinbase/payload_signature.rb', line 119

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

#to_sString

Returns a String representation of the Payload Signature.

Returns:

  • (String)

    a String representation of the Payload Signature



157
158
159
160
161
162
163
164
165
166
167
# File 'lib/coinbase/payload_signature.rb', line 157

def to_s
  Coinbase.pretty_print_object(
    self.class,
    id: id,
    wallet_id: wallet_id,
    address_id: address_id,
    status: status,
    unsigned_payload: unsigned_payload,
    signature: signature
  )
end

#unsigned_payloadString

Returns the Unsigned Payload of the Payload Signature.

Returns:

  • (String)

    The Unsigned Payload



101
102
103
# File 'lib/coinbase/payload_signature.rb', line 101

def unsigned_payload
  @model.unsigned_payload
end

#wait!(interval_seconds = 0.2, timeout_seconds = 20) ⇒ PayloadSignature

Waits until the Payload Signature is signed or failed by polling the server at the given interval. Raises a Timeout::Error if the Payload Signature takes longer than the given timeout. in seconds.

Parameters:

  • interval_seconds (Integer) (defaults to: 0.2)

    The interval at which to poll the server, in seconds

  • timeout_seconds (Integer) (defaults to: 20)

    The maximum amount of time to wait for the Payload Signature to be signed,

Returns:



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/coinbase/payload_signature.rb', line 139

def wait!(interval_seconds = 0.2, timeout_seconds = 20)
  start_time = Time.now

  loop do
    reload

    return self if terminal_state?

    raise Timeout::Error, 'Payload Signature timed out' if Time.now - start_time > timeout_seconds

    self.sleep interval_seconds
  end

  self
end

#wallet_idString

Returns the Wallet ID of the Payload Signature.

Returns:

  • (String)

    The Wallet ID



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

def wallet_id
  @model.wallet_id
end