Skip to content

Commit f766e78

Browse files
authored
Merge pull request #41 from piotr-iohk/construct-transaction
New tx workflow endpoints
2 parents 0c8ba73 + 7d90a65 commit f766e78

File tree

4 files changed

+82
-1
lines changed

4 files changed

+82
-1
lines changed

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ Metrics/CyclomaticComplexity:
2222

2323
Metrics/ParameterLists:
2424
Max: 10
25+
MaxOptionalParameters: 10

lib/cardano_wallet/byron.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,41 @@ def random(wid, payments)
210210
# Byron transactions
211211
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postByronTransactionFee
212212
class Transactions < Base
213+
# Construct transaction
214+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/constructByronTransaction
215+
# @param wid [String] source wallet id
216+
# @param payments [Array of Hashes] full payments payload with assets
217+
# @param metadata [Hash] special metadata JSON subset format (cf: https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransaction)
218+
# @param mint [Array of Hashes] mint object
219+
# @param validity_interval [Hash] validity_interval object
220+
def construct(wid, payments = nil, metadata = nil, mint = nil, validity_interval = nil)
221+
payload = {}
222+
payload[:payments] = payments if payments
223+
payload[:metadata] = metadata if metadata
224+
payload[:mint] = mint if mint
225+
payload[:validity_interval] = validity_interval if validity_interval
226+
227+
self.class.post("/byron-wallets/#{wid}/transactions-construct",
228+
body: payload.to_json,
229+
headers: { 'Content-Type' => 'application/json' })
230+
end
231+
232+
# Sign transaction
233+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/signByronTransaction
234+
# @param wid [String] source wallet id
235+
# @param passphrase [String] wallet's passphrase
236+
# @param passphrase [String] CBOR transaction data
237+
def sign(wid, passphrase, transaction)
238+
payload = {
239+
'passphrase' => passphrase,
240+
'transaction' => transaction
241+
}
242+
243+
self.class.post("/byron-wallets/#{wid}/transactions-sign",
244+
body: payload.to_json,
245+
headers: { 'Content-Type' => 'application/json' })
246+
end
247+
213248
# Get tx by id
214249
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getByronTransaction
215250
def get(wid, tx_id)

lib/cardano_wallet/shelley.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,51 @@ def random_deleg(wid, deleg_action)
258258
# API for Transactions
259259
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Transactions
260260
class Transactions < Base
261+
# Construct transaction
262+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/constructTransaction
263+
# @param wid [String] source wallet id
264+
# @param payments [Array of Hashes] full payments payload with assets
265+
# @param withdrawal [String or Array] 'self' or mnemonic sentence
266+
# @param metadata [Hash] special metadata JSON subset format (cf: https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransaction)
267+
# @param mint [Array of Hashes] mint object
268+
# @param delegations [Array of Hashes] delegations object
269+
# @param validity_interval [Hash] validity_interval object
270+
def construct(wid,
271+
payments = nil,
272+
withdrawal = nil,
273+
metadata = nil,
274+
delegations = nil,
275+
mint = nil,
276+
validity_interval = nil)
277+
payload = {}
278+
payload[:payments] = payments if payments
279+
payload[:withdrawal] = withdrawal if withdrawal
280+
payload[:metadata] = metadata if metadata
281+
payload[:mint] = mint if mint
282+
payload[:delegations] = delegations if delegations
283+
payload[:validity_interval] = validity_interval if validity_interval
284+
285+
self.class.post("/wallets/#{wid}/transactions-construct",
286+
body: payload.to_json,
287+
headers: { 'Content-Type' => 'application/json' })
288+
end
289+
290+
# Sign transaction
291+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/signTransaction
292+
# @param wid [String] source wallet id
293+
# @param passphrase [String] wallet's passphrase
294+
# @param passphrase [String] CBOR transaction data
295+
def sign(wid, passphrase, transaction)
296+
payload = {
297+
'passphrase' => passphrase,
298+
'transaction' => transaction
299+
}
300+
301+
self.class.post("/wallets/#{wid}/transactions-sign",
302+
body: payload.to_json,
303+
headers: { 'Content-Type' => 'application/json' })
304+
end
305+
261306
# Get tx by id
262307
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getTransaction
263308
def get(wid, tx_id)

lib/cardano_wallet/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module CardanoWallet
4-
VERSION = '0.3.12'
4+
VERSION = '0.3.14'
55
end

0 commit comments

Comments
 (0)