Skip to content

Commit

Permalink
Merge pull request #41 from piotr-iohk/construct-transaction
Browse files Browse the repository at this point in the history
New tx workflow endpoints
  • Loading branch information
piotr-iohk authored Jul 29, 2021
2 parents 0c8ba73 + 7d90a65 commit f766e78
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ Metrics/CyclomaticComplexity:

Metrics/ParameterLists:
Max: 10
MaxOptionalParameters: 10
35 changes: 35 additions & 0 deletions lib/cardano_wallet/byron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,41 @@ 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)
Expand Down
45 changes: 45 additions & 0 deletions lib/cardano_wallet/shelley.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,51 @@ 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
# @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

# 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)
Expand Down
2 changes: 1 addition & 1 deletion lib/cardano_wallet/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module CardanoWallet
VERSION = '0.3.12'
VERSION = '0.3.14'
end

0 comments on commit f766e78

Please sign in to comment.