coinbase-sdk 0.1.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/coinbase/address/wallet_address.rb +60 -4
- data/lib/coinbase/address.rb +35 -9
- data/lib/coinbase/client/api/addresses_api.rb +234 -1
- data/lib/coinbase/client/api/assets_api.rb +1 -1
- data/lib/coinbase/client/api/contract_events_api.rb +1 -1
- data/lib/coinbase/client/api/contract_invocations_api.rb +342 -0
- data/lib/coinbase/client/api/external_addresses_api.rb +83 -1
- data/lib/coinbase/client/api/networks_api.rb +1 -1
- data/lib/coinbase/client/api/server_signers_api.rb +1 -1
- data/lib/coinbase/client/api/stake_api.rb +1 -1
- data/lib/coinbase/client/api/trades_api.rb +1 -1
- data/lib/coinbase/client/api/transfers_api.rb +1 -1
- data/lib/coinbase/client/api/users_api.rb +1 -1
- data/lib/coinbase/client/api/validators_api.rb +1 -1
- data/lib/coinbase/client/api/wallet_stake_api.rb +1 -1
- data/lib/coinbase/client/api/wallets_api.rb +1 -1
- data/lib/coinbase/client/api/webhooks_api.rb +1 -1
- data/lib/coinbase/client/api_client.rb +1 -1
- data/lib/coinbase/client/api_error.rb +1 -1
- data/lib/coinbase/client/configuration.rb +1 -1
- data/lib/coinbase/client/models/address.rb +1 -1
- data/lib/coinbase/client/models/address_balance_list.rb +1 -1
- data/lib/coinbase/client/models/address_historical_balance_list.rb +1 -1
- data/lib/coinbase/client/models/address_list.rb +1 -1
- data/lib/coinbase/client/models/address_transaction_list.rb +258 -0
- data/lib/coinbase/client/models/asset.rb +1 -1
- data/lib/coinbase/client/models/balance.rb +1 -1
- data/lib/coinbase/client/models/broadcast_contract_invocation_request.rb +222 -0
- data/lib/coinbase/client/models/broadcast_staking_operation_request.rb +1 -1
- data/lib/coinbase/client/models/broadcast_trade_request.rb +1 -1
- data/lib/coinbase/client/models/broadcast_transfer_request.rb +1 -1
- data/lib/coinbase/client/models/build_staking_operation_request.rb +1 -1
- data/lib/coinbase/client/models/contract_event.rb +1 -1
- data/lib/coinbase/client/models/contract_event_list.rb +1 -1
- data/lib/coinbase/client/models/contract_invocation.rb +351 -0
- data/lib/coinbase/client/models/contract_invocation_list.rb +274 -0
- data/lib/coinbase/client/models/create_address_request.rb +1 -1
- data/lib/coinbase/client/models/create_contract_invocation_request.rb +266 -0
- data/lib/coinbase/client/models/create_payload_signature_request.rb +232 -0
- data/lib/coinbase/client/models/create_server_signer_request.rb +1 -1
- data/lib/coinbase/client/models/create_staking_operation_request.rb +1 -1
- data/lib/coinbase/client/models/create_trade_request.rb +1 -1
- data/lib/coinbase/client/models/create_transfer_request.rb +1 -1
- data/lib/coinbase/client/models/create_wallet_request.rb +1 -1
- data/lib/coinbase/client/models/create_wallet_request_wallet.rb +1 -1
- data/lib/coinbase/client/models/create_webhook_request.rb +29 -5
- data/lib/coinbase/client/models/error.rb +1 -1
- data/lib/coinbase/client/models/ethereum_transaction.rb +389 -0
- data/lib/coinbase/client/models/ethereum_transaction_access.rb +225 -0
- data/lib/coinbase/client/models/ethereum_transaction_access_list.rb +216 -0
- data/lib/coinbase/client/models/ethereum_transaction_flattened_trace.rb +378 -0
- data/lib/coinbase/client/models/ethereum_validator_metadata.rb +1 -1
- data/lib/coinbase/client/models/faucet_transaction.rb +1 -1
- data/lib/coinbase/client/models/feature_set.rb +1 -1
- data/lib/coinbase/client/models/fetch_historical_staking_balances200_response.rb +1 -1
- data/lib/coinbase/client/models/fetch_staking_rewards200_response.rb +1 -1
- data/lib/coinbase/client/models/fetch_staking_rewards_request.rb +1 -1
- data/lib/coinbase/client/models/get_staking_context_request.rb +1 -1
- data/lib/coinbase/client/models/historical_balance.rb +1 -1
- data/lib/coinbase/client/models/network.rb +3 -3
- data/lib/coinbase/client/models/network_identifier.rb +3 -2
- data/lib/coinbase/client/models/payload_signature.rb +335 -0
- data/lib/coinbase/client/models/payload_signature_list.rb +275 -0
- data/lib/coinbase/client/models/seed_creation_event.rb +1 -1
- data/lib/coinbase/client/models/seed_creation_event_result.rb +1 -1
- data/lib/coinbase/client/models/server_signer.rb +1 -1
- data/lib/coinbase/client/models/server_signer_event.rb +1 -1
- data/lib/coinbase/client/models/server_signer_event_event.rb +1 -1
- data/lib/coinbase/client/models/server_signer_event_list.rb +1 -1
- data/lib/coinbase/client/models/server_signer_list.rb +1 -1
- data/lib/coinbase/client/models/signature_creation_event.rb +1 -1
- data/lib/coinbase/client/models/signature_creation_event_result.rb +1 -1
- data/lib/coinbase/client/models/signed_voluntary_exit_message_metadata.rb +1 -1
- data/lib/coinbase/client/models/sponsored_send.rb +1 -1
- data/lib/coinbase/client/models/staking_balance.rb +1 -1
- data/lib/coinbase/client/models/staking_context.rb +1 -1
- data/lib/coinbase/client/models/staking_context_context.rb +1 -1
- data/lib/coinbase/client/models/staking_operation.rb +1 -1
- data/lib/coinbase/client/models/staking_operation_metadata.rb +1 -1
- data/lib/coinbase/client/models/staking_reward.rb +1 -1
- data/lib/coinbase/client/models/staking_reward_format.rb +1 -1
- data/lib/coinbase/client/models/staking_reward_usd_value.rb +1 -1
- data/lib/coinbase/client/models/trade.rb +1 -1
- data/lib/coinbase/client/models/trade_list.rb +1 -1
- data/lib/coinbase/client/models/transaction.rb +36 -7
- data/lib/coinbase/client/models/transaction_content.rb +104 -0
- data/lib/coinbase/client/models/transaction_type.rb +1 -1
- data/lib/coinbase/client/models/transfer.rb +1 -1
- data/lib/coinbase/client/models/transfer_list.rb +1 -1
- data/lib/coinbase/client/models/update_webhook_request.rb +2 -50
- data/lib/coinbase/client/models/user.rb +1 -1
- data/lib/coinbase/client/models/validator.rb +1 -1
- data/lib/coinbase/client/models/validator_details.rb +1 -1
- data/lib/coinbase/client/models/validator_list.rb +1 -1
- data/lib/coinbase/client/models/validator_status.rb +1 -1
- data/lib/coinbase/client/models/wallet.rb +1 -1
- data/lib/coinbase/client/models/wallet_list.rb +1 -1
- data/lib/coinbase/client/models/webhook.rb +15 -5
- data/lib/coinbase/client/models/webhook_event_filter.rb +1 -1
- data/lib/coinbase/client/models/webhook_event_type.rb +1 -1
- data/lib/coinbase/client/models/webhook_list.rb +1 -1
- data/lib/coinbase/client/version.rb +1 -1
- data/lib/coinbase/client.rb +15 -1
- data/lib/coinbase/constants.rb +3 -0
- data/lib/coinbase/contract_invocation.rb +234 -0
- data/lib/coinbase/payload_signature.rb +181 -0
- data/lib/coinbase/staking_operation.rb +26 -0
- data/lib/coinbase/transaction.rb +21 -0
- data/lib/coinbase/version.rb +1 -1
- data/lib/coinbase/wallet.rb +12 -7
- data/lib/coinbase/webhook.rb +17 -6
- data/lib/coinbase.rb +2 -0
- metadata +18 -2
@@ -4,7 +4,7 @@
|
|
4
4
|
#This is the OpenAPI 3.0 specification for the Coinbase Platform APIs, used in conjunction with the Coinbase Platform SDKs.
|
5
5
|
|
6
6
|
The version of the OpenAPI document: 0.0.1-alpha
|
7
|
-
|
7
|
+
|
8
8
|
Generated by: https://openapi-generator.tech
|
9
9
|
Generator version: 7.7.0
|
10
10
|
|
@@ -4,7 +4,7 @@
|
|
4
4
|
#This is the OpenAPI 3.0 specification for the Coinbase Platform APIs, used in conjunction with the Coinbase Platform SDKs.
|
5
5
|
|
6
6
|
The version of the OpenAPI document: 0.0.1-alpha
|
7
|
-
|
7
|
+
|
8
8
|
Generated by: https://openapi-generator.tech
|
9
9
|
Generator version: 7.7.0
|
10
10
|
|
@@ -4,7 +4,7 @@
|
|
4
4
|
#This is the OpenAPI 3.0 specification for the Coinbase Platform APIs, used in conjunction with the Coinbase Platform SDKs.
|
5
5
|
|
6
6
|
The version of the OpenAPI document: 0.0.1-alpha
|
7
|
-
|
7
|
+
|
8
8
|
Generated by: https://openapi-generator.tech
|
9
9
|
Generator version: 7.7.0
|
10
10
|
|
@@ -4,7 +4,7 @@
|
|
4
4
|
#This is the OpenAPI 3.0 specification for the Coinbase Platform APIs, used in conjunction with the Coinbase Platform SDKs.
|
5
5
|
|
6
6
|
The version of the OpenAPI document: 0.0.1-alpha
|
7
|
-
|
7
|
+
|
8
8
|
Generated by: https://openapi-generator.tech
|
9
9
|
Generator version: 7.7.0
|
10
10
|
|
data/lib/coinbase/client.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
#This is the OpenAPI 3.0 specification for the Coinbase Platform APIs, used in conjunction with the Coinbase Platform SDKs.
|
5
5
|
|
6
6
|
The version of the OpenAPI document: 0.0.1-alpha
|
7
|
-
|
7
|
+
|
8
8
|
Generated by: https://openapi-generator.tech
|
9
9
|
Generator version: 7.7.0
|
10
10
|
|
@@ -21,15 +21,21 @@ Coinbase::Client.autoload :Address, 'coinbase/client/models/address'
|
|
21
21
|
Coinbase::Client.autoload :AddressBalanceList, 'coinbase/client/models/address_balance_list'
|
22
22
|
Coinbase::Client.autoload :AddressHistoricalBalanceList, 'coinbase/client/models/address_historical_balance_list'
|
23
23
|
Coinbase::Client.autoload :AddressList, 'coinbase/client/models/address_list'
|
24
|
+
Coinbase::Client.autoload :AddressTransactionList, 'coinbase/client/models/address_transaction_list'
|
24
25
|
Coinbase::Client.autoload :Asset, 'coinbase/client/models/asset'
|
25
26
|
Coinbase::Client.autoload :Balance, 'coinbase/client/models/balance'
|
27
|
+
Coinbase::Client.autoload :BroadcastContractInvocationRequest, 'coinbase/client/models/broadcast_contract_invocation_request'
|
26
28
|
Coinbase::Client.autoload :BroadcastStakingOperationRequest, 'coinbase/client/models/broadcast_staking_operation_request'
|
27
29
|
Coinbase::Client.autoload :BroadcastTradeRequest, 'coinbase/client/models/broadcast_trade_request'
|
28
30
|
Coinbase::Client.autoload :BroadcastTransferRequest, 'coinbase/client/models/broadcast_transfer_request'
|
29
31
|
Coinbase::Client.autoload :BuildStakingOperationRequest, 'coinbase/client/models/build_staking_operation_request'
|
30
32
|
Coinbase::Client.autoload :ContractEvent, 'coinbase/client/models/contract_event'
|
31
33
|
Coinbase::Client.autoload :ContractEventList, 'coinbase/client/models/contract_event_list'
|
34
|
+
Coinbase::Client.autoload :ContractInvocation, 'coinbase/client/models/contract_invocation'
|
35
|
+
Coinbase::Client.autoload :ContractInvocationList, 'coinbase/client/models/contract_invocation_list'
|
32
36
|
Coinbase::Client.autoload :CreateAddressRequest, 'coinbase/client/models/create_address_request'
|
37
|
+
Coinbase::Client.autoload :CreateContractInvocationRequest, 'coinbase/client/models/create_contract_invocation_request'
|
38
|
+
Coinbase::Client.autoload :CreatePayloadSignatureRequest, 'coinbase/client/models/create_payload_signature_request'
|
33
39
|
Coinbase::Client.autoload :CreateServerSignerRequest, 'coinbase/client/models/create_server_signer_request'
|
34
40
|
Coinbase::Client.autoload :CreateStakingOperationRequest, 'coinbase/client/models/create_staking_operation_request'
|
35
41
|
Coinbase::Client.autoload :CreateTradeRequest, 'coinbase/client/models/create_trade_request'
|
@@ -38,6 +44,10 @@ Coinbase::Client.autoload :CreateWalletRequest, 'coinbase/client/models/create_w
|
|
38
44
|
Coinbase::Client.autoload :CreateWalletRequestWallet, 'coinbase/client/models/create_wallet_request_wallet'
|
39
45
|
Coinbase::Client.autoload :CreateWebhookRequest, 'coinbase/client/models/create_webhook_request'
|
40
46
|
Coinbase::Client.autoload :Error, 'coinbase/client/models/error'
|
47
|
+
Coinbase::Client.autoload :EthereumTransaction, 'coinbase/client/models/ethereum_transaction'
|
48
|
+
Coinbase::Client.autoload :EthereumTransactionAccess, 'coinbase/client/models/ethereum_transaction_access'
|
49
|
+
Coinbase::Client.autoload :EthereumTransactionAccessList, 'coinbase/client/models/ethereum_transaction_access_list'
|
50
|
+
Coinbase::Client.autoload :EthereumTransactionFlattenedTrace, 'coinbase/client/models/ethereum_transaction_flattened_trace'
|
41
51
|
Coinbase::Client.autoload :EthereumValidatorMetadata, 'coinbase/client/models/ethereum_validator_metadata'
|
42
52
|
Coinbase::Client.autoload :FaucetTransaction, 'coinbase/client/models/faucet_transaction'
|
43
53
|
Coinbase::Client.autoload :FeatureSet, 'coinbase/client/models/feature_set'
|
@@ -48,6 +58,8 @@ Coinbase::Client.autoload :GetStakingContextRequest, 'coinbase/client/models/get
|
|
48
58
|
Coinbase::Client.autoload :HistoricalBalance, 'coinbase/client/models/historical_balance'
|
49
59
|
Coinbase::Client.autoload :Network, 'coinbase/client/models/network'
|
50
60
|
Coinbase::Client.autoload :NetworkIdentifier, 'coinbase/client/models/network_identifier'
|
61
|
+
Coinbase::Client.autoload :PayloadSignature, 'coinbase/client/models/payload_signature'
|
62
|
+
Coinbase::Client.autoload :PayloadSignatureList, 'coinbase/client/models/payload_signature_list'
|
51
63
|
Coinbase::Client.autoload :SeedCreationEvent, 'coinbase/client/models/seed_creation_event'
|
52
64
|
Coinbase::Client.autoload :SeedCreationEventResult, 'coinbase/client/models/seed_creation_event_result'
|
53
65
|
Coinbase::Client.autoload :ServerSigner, 'coinbase/client/models/server_signer'
|
@@ -70,6 +82,7 @@ Coinbase::Client.autoload :StakingRewardUSDValue, 'coinbase/client/models/stakin
|
|
70
82
|
Coinbase::Client.autoload :Trade, 'coinbase/client/models/trade'
|
71
83
|
Coinbase::Client.autoload :TradeList, 'coinbase/client/models/trade_list'
|
72
84
|
Coinbase::Client.autoload :Transaction, 'coinbase/client/models/transaction'
|
85
|
+
Coinbase::Client.autoload :TransactionContent, 'coinbase/client/models/transaction_content'
|
73
86
|
Coinbase::Client.autoload :TransactionType, 'coinbase/client/models/transaction_type'
|
74
87
|
Coinbase::Client.autoload :Transfer, 'coinbase/client/models/transfer'
|
75
88
|
Coinbase::Client.autoload :TransferList, 'coinbase/client/models/transfer_list'
|
@@ -90,6 +103,7 @@ Coinbase::Client.autoload :WebhookList, 'coinbase/client/models/webhook_list'
|
|
90
103
|
Coinbase::Client.autoload :AddressesApi, 'coinbase/client/api/addresses_api'
|
91
104
|
Coinbase::Client.autoload :AssetsApi, 'coinbase/client/api/assets_api'
|
92
105
|
Coinbase::Client.autoload :ContractEventsApi, 'coinbase/client/api/contract_events_api'
|
106
|
+
Coinbase::Client.autoload :ContractInvocationsApi, 'coinbase/client/api/contract_invocations_api'
|
93
107
|
Coinbase::Client.autoload :ExternalAddressesApi, 'coinbase/client/api/external_addresses_api'
|
94
108
|
Coinbase::Client.autoload :NetworksApi, 'coinbase/client/api/networks_api'
|
95
109
|
Coinbase::Client.autoload :ServerSignersApi, 'coinbase/client/api/server_signers_api'
|
data/lib/coinbase/constants.rb
CHANGED
@@ -0,0 +1,234 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Coinbase
|
4
|
+
# A representation of a Contract Invocation.
|
5
|
+
class ContractInvocation
|
6
|
+
class << self
|
7
|
+
# Creates a new ContractInvocation object.
|
8
|
+
# @param address_id [String] The Address ID of the signing Address
|
9
|
+
# @param wallet_id [String] The Wallet ID associated with the signing Address
|
10
|
+
# @param contract_address [String] The contract address
|
11
|
+
# @param abi [Array<Hash>] The contract ABI
|
12
|
+
# @param method [String] The contract method
|
13
|
+
# @param args [Hash] The arguments to pass to the contract method.
|
14
|
+
# The keys should be the argument names, and the values should be the argument values.
|
15
|
+
# @return [ContractInvocation] The new Contract Invocation object
|
16
|
+
# @raise [Coinbase::ApiError] If the request to create the Contract Invocation fails
|
17
|
+
def create(
|
18
|
+
address_id:,
|
19
|
+
wallet_id:,
|
20
|
+
contract_address:,
|
21
|
+
abi:,
|
22
|
+
method:,
|
23
|
+
args: {}
|
24
|
+
)
|
25
|
+
model = Coinbase.call_api do
|
26
|
+
contract_invocation_api.create_contract_invocation(
|
27
|
+
wallet_id,
|
28
|
+
address_id,
|
29
|
+
contract_address: contract_address,
|
30
|
+
abi: abi.to_json,
|
31
|
+
method: method,
|
32
|
+
args: args.to_json
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
new(model)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Enumerates the payload signatures for a given address belonging to a wallet.
|
40
|
+
# The result is an enumerator that lazily fetches from the server, and can be iterated over,
|
41
|
+
# converted an array, etc...
|
42
|
+
# @return [Enumerable<Coinbase::ContractInvocation>] Enumerator that returns payload signatures
|
43
|
+
def list(wallet_id:, address_id:)
|
44
|
+
Coinbase::Pagination.enumerate(
|
45
|
+
->(page) { fetch_page(wallet_id, address_id, page) }
|
46
|
+
) do |contract_invocation|
|
47
|
+
new(contract_invocation)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def contract_invocation_api
|
54
|
+
Coinbase::Client::ContractInvocationsApi.new(Coinbase.configuration.api_client)
|
55
|
+
end
|
56
|
+
|
57
|
+
def fetch_page(wallet_id, address_id, page)
|
58
|
+
contract_invocation_api.list_contract_invocations(
|
59
|
+
wallet_id,
|
60
|
+
address_id,
|
61
|
+
limit: DEFAULT_PAGE_LIMIT,
|
62
|
+
page: page
|
63
|
+
)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Returns a new ContractInvocation object. Do not use this method directly.
|
68
|
+
# Instead use Coinbase::ContractInvocation.create.
|
69
|
+
# @param model [Coinbase::Client::ContractInvocation] The underlying Contract Invocation obejct
|
70
|
+
def initialize(model)
|
71
|
+
raise unless model.is_a?(Coinbase::Client::ContractInvocation)
|
72
|
+
|
73
|
+
@model = model
|
74
|
+
end
|
75
|
+
|
76
|
+
# Returns the Contract Invocation ID.
|
77
|
+
# @return [String] The Contract Invocation ID
|
78
|
+
def id
|
79
|
+
@model.contract_invocation_id
|
80
|
+
end
|
81
|
+
|
82
|
+
# Returns the Wallet ID of the Contract Invocation.
|
83
|
+
# @return [String] The Wallet ID
|
84
|
+
def wallet_id
|
85
|
+
@model.wallet_id
|
86
|
+
end
|
87
|
+
|
88
|
+
# Returns the Address ID of the Contract Invocation.
|
89
|
+
# @return [String] The Address ID
|
90
|
+
def address_id
|
91
|
+
@model.address_id
|
92
|
+
end
|
93
|
+
|
94
|
+
# Returns the Network of the Contract Invocation.
|
95
|
+
# @return [Coinbase::Network] The Network
|
96
|
+
def network
|
97
|
+
@network ||= Coinbase::Network.from_id(@model.network_id)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Returns the Contract Address of the Contract Invocation.
|
101
|
+
# @return [String] The Contract Address
|
102
|
+
def contract_address
|
103
|
+
@model.contract_address
|
104
|
+
end
|
105
|
+
|
106
|
+
# Returns the ABI of the Contract Invocation.
|
107
|
+
# @return [Array<Hash>] The ABI
|
108
|
+
def abi
|
109
|
+
JSON.parse(@model.abi)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Returns the method of the Contract Invocation.
|
113
|
+
# @return [String] The method
|
114
|
+
def method
|
115
|
+
@model.method
|
116
|
+
end
|
117
|
+
|
118
|
+
# Returns the arguments of the Contract Invocation.
|
119
|
+
# @return [Hash] The arguments
|
120
|
+
def args
|
121
|
+
JSON.parse(@model.args).transform_keys(&:to_sym)
|
122
|
+
end
|
123
|
+
|
124
|
+
# Returns the transaction.
|
125
|
+
# @return [Coinbase::Transaction] The Transfer transaction
|
126
|
+
def transaction
|
127
|
+
@transaction ||= Coinbase::Transaction.new(@model.transaction)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Returns the status of the Contract Invocation.
|
131
|
+
# @return [String] The status
|
132
|
+
def status
|
133
|
+
transaction.status
|
134
|
+
end
|
135
|
+
|
136
|
+
# Signs the Contract Invocation transaction with the given key.
|
137
|
+
# This is required before broadcasting the Contract Invocation when not using
|
138
|
+
# a Server-Signer.
|
139
|
+
# @param key [Eth::Key] The key to sign the ContractInvocation with
|
140
|
+
# @raise [RuntimeError] If the key is not an Eth::Key
|
141
|
+
# @return [ContractInvocation] The ContractInvocation object
|
142
|
+
def sign(key)
|
143
|
+
raise unless key.is_a?(Eth::Key)
|
144
|
+
|
145
|
+
transaction.sign(key)
|
146
|
+
|
147
|
+
self
|
148
|
+
end
|
149
|
+
|
150
|
+
# Broadcasts the ContractInvocation to the Network.
|
151
|
+
# @raise [RuntimeError] If the ContractInvocation is not signed
|
152
|
+
# @return [ContractInvocation] The ContractInvocation object
|
153
|
+
def broadcast!
|
154
|
+
raise TransactionNotSignedError unless transaction.signed?
|
155
|
+
|
156
|
+
@model = Coinbase.call_api do
|
157
|
+
contract_invocation_api.broadcast_contract_invocation(
|
158
|
+
wallet_id,
|
159
|
+
address_id,
|
160
|
+
id,
|
161
|
+
{ signed_payload: transaction.signature }
|
162
|
+
)
|
163
|
+
end
|
164
|
+
|
165
|
+
@transaction = Coinbase::Transaction.new(@model.transaction)
|
166
|
+
|
167
|
+
self
|
168
|
+
end
|
169
|
+
|
170
|
+
# # Reload reloads the Contract Invocation model with the latest version from the server side.
|
171
|
+
# @return [ContractInvocation] The most recent version of Contract Invocation from the server
|
172
|
+
def reload
|
173
|
+
@model = Coinbase.call_api do
|
174
|
+
contract_invocation_api.get_contract_invocation(wallet_id, address_id, id)
|
175
|
+
end
|
176
|
+
|
177
|
+
@transaction = Coinbase::Transaction.new(@model.transaction)
|
178
|
+
|
179
|
+
self
|
180
|
+
end
|
181
|
+
|
182
|
+
# Waits until the Contract Invocation is signed or failed by polling the server at the given interval. Raises a
|
183
|
+
# Timeout::Error if the Contract Invocation takes longer than the given timeout.
|
184
|
+
# @param interval_seconds [Integer] The interval at which to poll the server, in seconds
|
185
|
+
# @param timeout_seconds [Integer] The maximum amount of time to wait for the Contract Invocation to be signed,
|
186
|
+
# in seconds.
|
187
|
+
# @return [ContractInvocation] The completed Contract Invocation object
|
188
|
+
def wait!(interval_seconds = 0.2, timeout_seconds = 20)
|
189
|
+
start_time = Time.now
|
190
|
+
|
191
|
+
loop do
|
192
|
+
reload
|
193
|
+
|
194
|
+
return self if transaction.terminal_state?
|
195
|
+
|
196
|
+
raise Timeout::Error, 'Contract Invocation timed out' if Time.now - start_time > timeout_seconds
|
197
|
+
|
198
|
+
self.sleep interval_seconds
|
199
|
+
end
|
200
|
+
|
201
|
+
self
|
202
|
+
end
|
203
|
+
|
204
|
+
# Returns a String representation of the Contract Invocation.
|
205
|
+
# @return [String] a String representation of the Contract Invocation
|
206
|
+
def to_s
|
207
|
+
Coinbase.pretty_print_object(
|
208
|
+
self.class,
|
209
|
+
id: id,
|
210
|
+
wallet_id: wallet_id,
|
211
|
+
address_id: address_id,
|
212
|
+
network_id: network.id,
|
213
|
+
status: status,
|
214
|
+
abi: abi.to_json,
|
215
|
+
method: method,
|
216
|
+
args: args.to_json,
|
217
|
+
transaction_hash: transaction.transaction_hash,
|
218
|
+
transaction_link: transaction.transaction_link
|
219
|
+
)
|
220
|
+
end
|
221
|
+
|
222
|
+
# Same as to_s.
|
223
|
+
# @return [String] a String representation of the ContractInvocation
|
224
|
+
def inspect
|
225
|
+
to_s
|
226
|
+
end
|
227
|
+
|
228
|
+
private
|
229
|
+
|
230
|
+
def contract_invocation_api
|
231
|
+
@contract_invocation_api ||= Coinbase::Client::ContractInvocationsApi.new(Coinbase.configuration.api_client)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'constants'
|
4
|
+
|
5
|
+
module Coinbase
|
6
|
+
# A representation of a Payload Signature.
|
7
|
+
class PayloadSignature
|
8
|
+
# A representation of a Payload Signature status.
|
9
|
+
module Status
|
10
|
+
# The Payload Signature is pending signing.
|
11
|
+
# At this point, the Signature is not available yet.
|
12
|
+
PENDING = 'pending'
|
13
|
+
|
14
|
+
# The Payload Signature has been signed.
|
15
|
+
SIGNED = 'signed'
|
16
|
+
|
17
|
+
# The Payload Signature has failed.
|
18
|
+
FAILED = 'failed'
|
19
|
+
|
20
|
+
# The states that are considered terminal.
|
21
|
+
TERMINAL_STATES = [SIGNED, FAILED].freeze
|
22
|
+
end
|
23
|
+
|
24
|
+
class << self
|
25
|
+
# Creates a new PayloadSignature object.
|
26
|
+
# @param wallet_id [String] The Wallet ID associated with the signing Address
|
27
|
+
# @param address_id [String] The Address ID of the signing Address
|
28
|
+
# @param unsigned_payload [String] The hex-encoded Unsigned Payload
|
29
|
+
# @param signature [String] (Optional) The Signature if the Wallet is not using an MPC Server-Signer
|
30
|
+
# @return [PayloadSignature] The new Payload Signature object
|
31
|
+
# @raise [Coinbase::ApiError] If the request to create the Payload Signature fails
|
32
|
+
def create(wallet_id:, address_id:, unsigned_payload:, signature: nil)
|
33
|
+
create_payload_signature_request = {
|
34
|
+
unsigned_payload: unsigned_payload,
|
35
|
+
signature: signature
|
36
|
+
}.compact
|
37
|
+
|
38
|
+
model = Coinbase.call_api do
|
39
|
+
addresses_api.create_payload_signature(
|
40
|
+
wallet_id,
|
41
|
+
address_id,
|
42
|
+
create_payload_signature_request: create_payload_signature_request
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
new(model)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Enumerates the payload signatures for a given address belonging to a wallet.
|
50
|
+
# The result is an enumerator that lazily fetches from the server, and can be iterated over,
|
51
|
+
# converted an array, etc...
|
52
|
+
# @return [Enumerable<Coinbase::PayloadSignature>] Enumerator that returns payload signatures
|
53
|
+
def list(wallet_id:, address_id:)
|
54
|
+
Coinbase::Pagination.enumerate(
|
55
|
+
->(page) { fetch_page(wallet_id, address_id, page) }
|
56
|
+
) do |payload_signature|
|
57
|
+
new(payload_signature)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def addresses_api
|
64
|
+
Coinbase::Client::AddressesApi.new(Coinbase.configuration.api_client)
|
65
|
+
end
|
66
|
+
|
67
|
+
def fetch_page(wallet_id, address_id, page)
|
68
|
+
addresses_api.list_payload_signatures(wallet_id, address_id, { limit: DEFAULT_PAGE_LIMIT, page: page })
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns a new PayloadSignature object. Do not use this method directly.
|
73
|
+
# Instead use Coinbase::PayloadSignature.create.
|
74
|
+
# @param model [Coinbase::Client::PayloadSignature] The underlying Payload Signature obejct
|
75
|
+
def initialize(model)
|
76
|
+
raise unless model.is_a?(Coinbase::Client::PayloadSignature)
|
77
|
+
|
78
|
+
@model = model
|
79
|
+
end
|
80
|
+
|
81
|
+
# Returns the Payload Signature ID.
|
82
|
+
# @return [String] The Payload Signature ID
|
83
|
+
def id
|
84
|
+
@model.payload_signature_id
|
85
|
+
end
|
86
|
+
|
87
|
+
# Returns the Wallet ID of the Payload Signature.
|
88
|
+
# @return [String] The Wallet ID
|
89
|
+
def wallet_id
|
90
|
+
@model.wallet_id
|
91
|
+
end
|
92
|
+
|
93
|
+
# Returns the Address ID of the Payload Signature.
|
94
|
+
# @return [String] The Address ID
|
95
|
+
def address_id
|
96
|
+
@model.address_id
|
97
|
+
end
|
98
|
+
|
99
|
+
# Returns the Unsigned Payload of the Payload Signature.
|
100
|
+
# @return [String] The Unsigned Payload
|
101
|
+
def unsigned_payload
|
102
|
+
@model.unsigned_payload
|
103
|
+
end
|
104
|
+
|
105
|
+
# Returns the Signature of the Payload Signature.
|
106
|
+
# @return [String] The Signature
|
107
|
+
def signature
|
108
|
+
@model.signature
|
109
|
+
end
|
110
|
+
|
111
|
+
# Returns the status of the Payload Signature.
|
112
|
+
# @return [Symbol] The status
|
113
|
+
def status
|
114
|
+
@model.status
|
115
|
+
end
|
116
|
+
|
117
|
+
# Returns whether the Payload Signature is in a terminal state.
|
118
|
+
# @return [Boolean] Whether the Payload Signature is in a terminal state
|
119
|
+
def terminal_state?
|
120
|
+
Status::TERMINAL_STATES.include?(status)
|
121
|
+
end
|
122
|
+
|
123
|
+
# # Reload reloads the Payload Signature model with the latest version from the server side.
|
124
|
+
# @return [PayloadSignature] The most recent version of Payload Signature from the server
|
125
|
+
def reload
|
126
|
+
@model = Coinbase.call_api do
|
127
|
+
addresses_api.get_payload_signature(wallet_id, address_id, id)
|
128
|
+
end
|
129
|
+
|
130
|
+
self
|
131
|
+
end
|
132
|
+
|
133
|
+
# Waits until the Payload Signature is signed or failed by polling the server at the given interval. Raises a
|
134
|
+
# Timeout::Error if the Payload Signature takes longer than the given timeout.
|
135
|
+
# @param interval_seconds [Integer] The interval at which to poll the server, in seconds
|
136
|
+
# @param timeout_seconds [Integer] The maximum amount of time to wait for the Payload Signature to be signed,
|
137
|
+
# in seconds.
|
138
|
+
# @return [PayloadSignature] The completed Payload Signature object
|
139
|
+
def wait!(interval_seconds = 0.2, timeout_seconds = 20)
|
140
|
+
start_time = Time.now
|
141
|
+
|
142
|
+
loop do
|
143
|
+
reload
|
144
|
+
|
145
|
+
return self if terminal_state?
|
146
|
+
|
147
|
+
raise Timeout::Error, 'Payload Signature timed out' if Time.now - start_time > timeout_seconds
|
148
|
+
|
149
|
+
self.sleep interval_seconds
|
150
|
+
end
|
151
|
+
|
152
|
+
self
|
153
|
+
end
|
154
|
+
|
155
|
+
# Returns a String representation of the Payload Signature.
|
156
|
+
# @return [String] a String representation of the Payload Signature
|
157
|
+
def to_s
|
158
|
+
Coinbase.pretty_print_object(
|
159
|
+
self.class,
|
160
|
+
id: id,
|
161
|
+
wallet_id: wallet_id,
|
162
|
+
address_id: address_id,
|
163
|
+
status: status,
|
164
|
+
unsigned_payload: unsigned_payload,
|
165
|
+
signature: signature
|
166
|
+
)
|
167
|
+
end
|
168
|
+
|
169
|
+
# Same as to_s.
|
170
|
+
# @return [String] a String representation of the PayloadSignature
|
171
|
+
def inspect
|
172
|
+
to_s
|
173
|
+
end
|
174
|
+
|
175
|
+
private
|
176
|
+
|
177
|
+
def addresses_api
|
178
|
+
Coinbase::Client::AddressesApi.new(Coinbase.configuration.api_client)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
@@ -17,6 +17,19 @@ module Coinbase
|
|
17
17
|
# @param action [Symbol] The action to perform
|
18
18
|
# @param mode [Symbol] The staking mode
|
19
19
|
# @param options [Hash] Additional options
|
20
|
+
# @option options [String] :integrator_contract_address The integrator contract
|
21
|
+
# address. [asset_id: :eth, mode: :partial, action: all]
|
22
|
+
# @option options [String] :funding_address The address funding the 32 ETH
|
23
|
+
# (default: :address_id) [asset_id: :eth, mode: :native, action: :stake]
|
24
|
+
# @option options [String] :withdrawal_address The address receiving rewards and withdrawal funds.
|
25
|
+
# (default: :address_id) [asset_id: :eth, mode: :native, action: :stake]
|
26
|
+
# @option options [String] :fee_recipient_address The address receiving transaction fees.
|
27
|
+
# (default: :address_id) [asset_id: :eth, mode: :native, action: :stake]
|
28
|
+
# @option options [Boolean] :immediate To leverage "Coinbase Managed Unstake".
|
29
|
+
# (default: false i.e. User Managed Unstake) [asset_id: :eth, mode: :native, action: :unstake]
|
30
|
+
# @option options [String] :validator_pub_keys List of comma separated validator public keys to unstake.
|
31
|
+
# (default: validators picked up on your behalf corresponding to the unstake amount.) [asset_id: :eth,
|
32
|
+
# mode: :native, action: :unstake]
|
20
33
|
# @return [Coinbase::StakingOperation] The staking operation
|
21
34
|
def self.build(amount, network, asset_id, address_id, action, mode, options)
|
22
35
|
network = Coinbase::Network.from_id(network)
|
@@ -49,6 +62,19 @@ module Coinbase
|
|
49
62
|
# @param action [Symbol] The action to perform
|
50
63
|
# @param mode [Symbol] The staking mode
|
51
64
|
# @param options [Hash] Additional options
|
65
|
+
# @option options [String] :integrator_contract_address The integrator contract
|
66
|
+
# address. [asset_id: :eth, mode: :partial, action: all]
|
67
|
+
# @option options [String] :funding_address The address funding the 32 ETH
|
68
|
+
# (default: :address_id) [asset_id: :eth, mode: :native, action: :stake]
|
69
|
+
# @option options [String] :withdrawal_address The address receiving rewards and withdrawal funds.
|
70
|
+
# (default: :address_id) [asset_id: :eth, mode: :native, action: :stake]
|
71
|
+
# @option options [String] :fee_recipient_address The address receiving transaction fees.
|
72
|
+
# (default: :address_id) [asset_id: :eth, mode: :native, action: :stake]
|
73
|
+
# @option options [Boolean] :immediate To leverage "Coinbase Managed Unstake".
|
74
|
+
# (default: false i.e. User Managed Unstake) [asset_id: :eth, mode: :native, action: :unstake]
|
75
|
+
# @option options [String] :validator_pub_keys List of comma separated validator public keys to unstake.
|
76
|
+
# (default: validators picked up on your behalf corresponding to the unstake amount.) [asset_id: :eth,
|
77
|
+
# mode: :native, action: :unstake]
|
52
78
|
# @return [Coinbase::StakingOperation] The staking operation
|
53
79
|
def self.create(amount, network, asset_id, address_id, wallet_id, action, mode, options)
|
54
80
|
network = Coinbase::Network.from_id(network)
|
data/lib/coinbase/transaction.rb
CHANGED
@@ -26,6 +26,9 @@ module Coinbase
|
|
26
26
|
# The Transaction has failed for some reason.
|
27
27
|
FAILED = 'failed'
|
28
28
|
|
29
|
+
# The Transaction isn't specified it's status in Receipt.
|
30
|
+
UNSPECIFIED = 'unspecified'
|
31
|
+
|
29
32
|
# The states that are considered terminal on-chain.
|
30
33
|
TERMINAL_STATES = [COMPLETE, FAILED].freeze
|
31
34
|
end
|
@@ -80,12 +83,30 @@ module Coinbase
|
|
80
83
|
Status::TERMINAL_STATES.include?(status)
|
81
84
|
end
|
82
85
|
|
86
|
+
# Returns the block hash of which the Transaction is recorded.
|
87
|
+
# @return [String] The to block_hash
|
88
|
+
def block_hash
|
89
|
+
@model.block_hash
|
90
|
+
end
|
91
|
+
|
92
|
+
# Returns the block height of which the Transaction is recorded.
|
93
|
+
# @return [String] The to block_height
|
94
|
+
def block_height
|
95
|
+
@model.block_height
|
96
|
+
end
|
97
|
+
|
83
98
|
# Returns the link to the transaction on the blockchain explorer.
|
84
99
|
# @return [String] The link to the transaction on the blockchain explorer
|
85
100
|
def transaction_link
|
86
101
|
@model.transaction_link
|
87
102
|
end
|
88
103
|
|
104
|
+
# Returns the block height of which the Transaction is recorded.
|
105
|
+
# @return [String] The to block_height
|
106
|
+
def content
|
107
|
+
@model.content
|
108
|
+
end
|
109
|
+
|
89
110
|
# Returns the underlying raw transaction.
|
90
111
|
# @return [Eth::Tx::Eip1559] The raw transaction
|
91
112
|
def raw
|
data/lib/coinbase/version.rb
CHANGED
data/lib/coinbase/wallet.rb
CHANGED
@@ -162,6 +162,7 @@ module Coinbase
|
|
162
162
|
# @return [Coinbase::Trade] The Trade object.
|
163
163
|
|
164
164
|
# @!method faucet
|
165
|
+
# @param asset_id [Symbol] The ID of the Asset to transfer to the wallet.
|
165
166
|
# Requests funds from the faucet for the Wallet's default address and returns the faucet transaction.
|
166
167
|
# This is only supported on testnet networks.
|
167
168
|
# @return [Coinbase::FaucetTransaction] The successful faucet transaction
|
@@ -225,8 +226,18 @@ module Coinbase
|
|
225
226
|
# @param options [Hash] Additional options for the staking operation
|
226
227
|
# @return [BigDecimal] The claimable balance
|
227
228
|
|
229
|
+
# @!method sign_payload
|
230
|
+
# Signs the given unsigned payload.
|
231
|
+
# @param unsigned_payload [String] The hex-encoded hashed unsigned payload for the Address to sign.
|
232
|
+
# @return [Coinbase::PayloadSignature] The payload signature
|
233
|
+
|
234
|
+
# @!method invoke_contract
|
235
|
+
# Invokes a contract with the given ABI, method, and arguments.
|
236
|
+
# @param abi [Array<Hash>] The ABI of the contract
|
237
|
+
#
|
238
|
+
|
228
239
|
def_delegators :default_address, :transfer, :trade, :faucet, :stake, :unstake, :claim_stake, :staking_balances,
|
229
|
-
:stakeable_balance, :unstakeable_balance, :claimable_balance
|
240
|
+
:stakeable_balance, :unstakeable_balance, :claimable_balance, :sign_payload, :invoke_contract
|
230
241
|
|
231
242
|
# Returns the addresses belonging to the Wallet.
|
232
243
|
# @return [Array<Coinbase::WalletAddress>] The addresses belonging to the Wallet
|
@@ -363,12 +374,6 @@ module Coinbase
|
|
363
374
|
Data.new(wallet_id: id, seed: @master.seed_hex)
|
364
375
|
end
|
365
376
|
|
366
|
-
def faucet
|
367
|
-
Coinbase.call_api do
|
368
|
-
Coinbase::FaucetTransaction.new(addresses_api.request_faucet_funds(id, default_address.id))
|
369
|
-
end
|
370
|
-
end
|
371
|
-
|
372
377
|
# Returns whether the Wallet has a seed with which to derive keys and sign transactions.
|
373
378
|
# @return [Boolean] Whether the Wallet has a seed with which to derive keys and sign transactions.
|
374
379
|
def can_sign?
|