From 2b35d428048eb37c948ac644bca1e2fd4c3b1b83 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Wed, 7 Jul 2021 14:59:14 +0200 Subject: [PATCH 1/4] construct ep - shelley --- lib/cardano_wallet/shelley.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/cardano_wallet/shelley.rb b/lib/cardano_wallet/shelley.rb index 8736e47..3d708cf 100644 --- a/lib/cardano_wallet/shelley.rb +++ b/lib/cardano_wallet/shelley.rb @@ -258,6 +258,31 @@ def random_deleg(wid, deleg_action) # API for Transactions # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Transactions class Transactions < Base + + # Construct transaction + # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransactionConstruct + # @param wid [String] source wallet id + # @param passphrase [String] source wallet's passphrase + # @param payments [Array of Hashes] full payments payload with assets + # @param withdrawal [String or Array] 'self' or mnemonic sentence + # @param metadata [Hash] special metadata JSON subset format (cf: https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransaction) + # @param mint [Array of Hashes] mint object + # @param delegations [Array of Hashes] delegations object + # @param validity_interval [Hash] validity_interval object + def construct(wid, payments = nil, withdrawal = nil, metadata = nil, delegations = nil, mint = nil, validity_interval = nil) + payload = {} + payload[:payments] = payments if payments + payload[:withdrawal] = withdrawal if withdrawal + payload[:metadata] = metadata if metadata + payload[:mint] = mint if mint + payload[:delegations] = delegations if delegations + payload[:validity_interval] = validity_interval if validity_interval + + self.class.post("/wallets/#{wid}/transactions-construct", + body: payload.to_json, + headers: { 'Content-Type' => 'application/json' }) + end + # Get tx by id # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getTransaction def get(wid, tx_id) From 4b4c672464b825c6efbc7bff2619ec4afcfa5456 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Wed, 7 Jul 2021 15:04:34 +0200 Subject: [PATCH 2/4] sign tx ep - shelley --- lib/cardano_wallet/shelley.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/cardano_wallet/shelley.rb b/lib/cardano_wallet/shelley.rb index 3d708cf..161f113 100644 --- a/lib/cardano_wallet/shelley.rb +++ b/lib/cardano_wallet/shelley.rb @@ -260,9 +260,8 @@ def random_deleg(wid, deleg_action) class Transactions < Base # Construct transaction - # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransactionConstruct + # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/constructTransaction # @param wid [String] source wallet id - # @param passphrase [String] source wallet's passphrase # @param payments [Array of Hashes] full payments payload with assets # @param withdrawal [String or Array] 'self' or mnemonic sentence # @param metadata [Hash] special metadata JSON subset format (cf: https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransaction) @@ -283,6 +282,22 @@ def construct(wid, payments = nil, withdrawal = nil, metadata = nil, delegations headers: { 'Content-Type' => 'application/json' }) end + # Sign transaction + # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/signTransaction + # @param wid [String] source wallet id + # @param passphrase [String] wallet's passphrase + # @param passphrase [String] CBOR transaction data + def sign(wid, passphrase, transaction) + payload = { + "passphrase" => passphrase, + "transaction" => transaction + } + + self.class.post("/wallets/#{wid}/transactions-sign", + body: payload.to_json, + headers: { 'Content-Type' => 'application/json' }) + end + # Get tx by id # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getTransaction def get(wid, tx_id) From 1d90c44347874e2bb61366780badda43b09f8f36 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 9 Jul 2021 09:47:42 +0200 Subject: [PATCH 3/4] construct/sign tx - byron --- lib/cardano_wallet/byron.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/cardano_wallet/byron.rb b/lib/cardano_wallet/byron.rb index a68c6c0..fa4e2cd 100644 --- a/lib/cardano_wallet/byron.rb +++ b/lib/cardano_wallet/byron.rb @@ -210,6 +210,42 @@ def random(wid, payments) # Byron transactions # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postByronTransactionFee class Transactions < Base + + # Construct transaction + # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/constructByronTransaction + # @param wid [String] source wallet id + # @param payments [Array of Hashes] full payments payload with assets + # @param metadata [Hash] special metadata JSON subset format (cf: https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransaction) + # @param mint [Array of Hashes] mint object + # @param validity_interval [Hash] validity_interval object + def construct(wid, payments = nil, metadata = nil, mint = nil, validity_interval = nil) + payload = {} + payload[:payments] = payments if payments + payload[:metadata] = metadata if metadata + payload[:mint] = mint if mint + payload[:validity_interval] = validity_interval if validity_interval + + self.class.post("/byron-wallets/#{wid}/transactions-construct", + body: payload.to_json, + headers: { 'Content-Type' => 'application/json' }) + end + + # Sign transaction + # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/signByronTransaction + # @param wid [String] source wallet id + # @param passphrase [String] wallet's passphrase + # @param passphrase [String] CBOR transaction data + def sign(wid, passphrase, transaction) + payload = { + "passphrase" => passphrase, + "transaction" => transaction + } + + self.class.post("/byron-wallets/#{wid}/transactions-sign", + body: payload.to_json, + headers: { 'Content-Type' => 'application/json' }) + end + # Get tx by id # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getByronTransaction def get(wid, tx_id) From 7d90a6598348e6309e9037e184b26cf67e0e0eef Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Thu, 29 Jul 2021 14:02:22 +0200 Subject: [PATCH 4/4] satisfy rubocop and version bump to 3.14 --- .rubocop.yml | 1 + lib/cardano_wallet/byron.rb | 5 ++--- lib/cardano_wallet/shelley.rb | 13 +++++++++---- lib/cardano_wallet/version.rb | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index d2e656e..8d30182 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -22,3 +22,4 @@ Metrics/CyclomaticComplexity: Metrics/ParameterLists: Max: 10 + MaxOptionalParameters: 10 diff --git a/lib/cardano_wallet/byron.rb b/lib/cardano_wallet/byron.rb index fa4e2cd..8b753c0 100644 --- a/lib/cardano_wallet/byron.rb +++ b/lib/cardano_wallet/byron.rb @@ -210,7 +210,6 @@ def random(wid, payments) # Byron transactions # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postByronTransactionFee class Transactions < Base - # Construct transaction # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/constructByronTransaction # @param wid [String] source wallet id @@ -237,8 +236,8 @@ def construct(wid, payments = nil, metadata = nil, mint = nil, validity_interval # @param passphrase [String] CBOR transaction data def sign(wid, passphrase, transaction) payload = { - "passphrase" => passphrase, - "transaction" => transaction + 'passphrase' => passphrase, + 'transaction' => transaction } self.class.post("/byron-wallets/#{wid}/transactions-sign", diff --git a/lib/cardano_wallet/shelley.rb b/lib/cardano_wallet/shelley.rb index 161f113..a7a28e8 100644 --- a/lib/cardano_wallet/shelley.rb +++ b/lib/cardano_wallet/shelley.rb @@ -258,7 +258,6 @@ def random_deleg(wid, deleg_action) # API for Transactions # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Transactions class Transactions < Base - # Construct transaction # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/constructTransaction # @param wid [String] source wallet id @@ -268,7 +267,13 @@ class Transactions < Base # @param mint [Array of Hashes] mint object # @param delegations [Array of Hashes] delegations object # @param validity_interval [Hash] validity_interval object - def construct(wid, payments = nil, withdrawal = nil, metadata = nil, delegations = nil, mint = nil, validity_interval = nil) + def construct(wid, + payments = nil, + withdrawal = nil, + metadata = nil, + delegations = nil, + mint = nil, + validity_interval = nil) payload = {} payload[:payments] = payments if payments payload[:withdrawal] = withdrawal if withdrawal @@ -289,8 +294,8 @@ def construct(wid, payments = nil, withdrawal = nil, metadata = nil, delegations # @param passphrase [String] CBOR transaction data def sign(wid, passphrase, transaction) payload = { - "passphrase" => passphrase, - "transaction" => transaction + 'passphrase' => passphrase, + 'transaction' => transaction } self.class.post("/wallets/#{wid}/transactions-sign", diff --git a/lib/cardano_wallet/version.rb b/lib/cardano_wallet/version.rb index 8edf832..ac49487 100644 --- a/lib/cardano_wallet/version.rb +++ b/lib/cardano_wallet/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module CardanoWallet - VERSION = '0.3.12' + VERSION = '0.3.14' end