Class: CardanoWallet::Shelley::Transactions

Inherits:
Base
  • Object
show all
Defined in:
lib/cardano_wallet/shelley.rb

Overview

API for Transactions

Examples:

@cw = CardanoWallet.new
@cw.shelley.transactions # API for Shelley Transactions

See Also:

Instance Attribute Summary

Attributes inherited from Base

#opt

Instance Method Summary collapse

Methods inherited from Base

#byron, #initialize, #misc, #shared, #shelley, #utils

Constructor Details

This class inherits a constructor from CardanoWallet::Base

Instance Method Details

#balance(wid, payload) ⇒ Object

Balance transaction

Parameters:

  • wid (String)

    source wallet id

  • payload (Hash)

    payload object

See Also:



306
307
308
309
310
# File 'lib/cardano_wallet/shelley.rb', line 306

def balance(wid, payload)
  self.class.post("/wallets/#{wid}/transactions-balance",
                  body: payload.to_json,
                  headers: { 'Content-Type' => 'application/json' })
end

#construct(wid, payments = nil, withdrawal = nil, metadata = nil, delegations = nil, mint = nil, validity_interval = nil, encoding = nil) ⇒ Object

Construct transaction

Parameters:

  • wid (String)

    source wallet id

  • payments (Array of Hashes) (defaults to: nil)

    full payments payload with assets

  • withdrawal (String or Array) (defaults to: nil)

    ‘self’ or mnemonic sentence

  • metadata (Hash) (defaults to: nil)
  • mint (Array of Hashes) (defaults to: nil)

    mint object

  • delegations (Array of Hashes) (defaults to: nil)

    delegations object

  • validity_interval (Hash) (defaults to: nil)

    validity_interval object

  • encoding (String) (defaults to: nil)

    output encoding (“base16” or “base64”)

See Also:



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'lib/cardano_wallet/shelley.rb', line 334

def construct(wid,
              payments = nil,
              withdrawal = nil,
               = nil,
              delegations = nil,
              mint = nil,
              validity_interval = nil,
              encoding = nil)
  payload = {}
  payload[:payments] = payments if payments
  payload[:withdrawal] = withdrawal if withdrawal
  payload[:metadata] =  if 
  payload[:mint_burn] = mint if mint
  payload[:delegations] = delegations if delegations
  payload[:validity_interval] = validity_interval if validity_interval
  payload[:encoding] = encoding if encoding

  self.class.post("/wallets/#{wid}/transactions-construct",
                  body: payload.to_json,
                  headers: { 'Content-Type' => 'application/json' })
end

#create(wid, passphrase, payments, withdrawal = nil, metadata = nil, ttl = nil) ⇒ Object

Create a transaction from the wallet

Examples:

create(wid, passphrase, [{addr1: 1000000}, {addr2: 1000000}], 'self', {"1": "abc"}, ttl = 10)
create(wid, passphrase, [{ "address": "addr1..",
                           "amount": { "quantity": 42000000, "unit": "lovelace" },
                           "assets": [{"policy_id": "pid", "asset_name": "name", "quantity": 0 } ] } ],
                           'self', {"1": "abc"}, ttl = 10)

Parameters:

  • wid (String)

    source wallet id

  • passphrase (String)

    source wallet’s passphrase

  • payments (Array of Hashes)

    address / amount list or full payments payload with assets

  • withdrawal (String or Array) (defaults to: nil)

    ‘self’ or mnemonic sentence

  • metadata (Hash) (defaults to: nil)
  • ttl (Int) (defaults to: nil)

    transaction’s time-to-live in seconds

See Also:



416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/cardano_wallet/shelley.rb', line 416

def create(wid, passphrase, payments, withdrawal = nil,  = nil, ttl = nil)
  Utils.verify_param_is_array!(payments)
  payments_formatted = if payments.any? { |p| p.key?(:address) || p.key?('address') }
                         payments
                       else
                         Utils.format_payments(payments)
                       end
  payload = { payments: payments_formatted,
              passphrase: passphrase }
  payload[:withdrawal] = withdrawal if withdrawal
  payload[:metadata] =  if 
  payload[:time_to_live] = { quantity: ttl, unit: 'second' } if ttl

  self.class.post("/wallets/#{wid}/transactions",
                  body: payload.to_json,
                  headers: { 'Content-Type' => 'application/json' })
end

#decode(wid, transaction) ⇒ Object

Decode transaction

Parameters:

  • wid (String)

    source wallet id

  • transaction (String)

    CBOR base64|base16 encoded transaction

See Also:



316
317
318
319
320
321
322
# File 'lib/cardano_wallet/shelley.rb', line 316

def decode(wid, transaction)
  payload = {}
  payload[:transaction] = transaction
  self.class.post("/wallets/#{wid}/transactions-decode",
                  body: payload.to_json,
                  headers: { 'Content-Type' => 'application/json' })
end

#forget(wid, txid) ⇒ Object

Forget a transaction



464
465
466
# File 'lib/cardano_wallet/shelley.rb', line 464

def forget(wid, txid)
  self.class.delete("/wallets/#{wid}/transactions/#{txid}")
end

#get(wid, tx_id, query = {}) ⇒ Object

Get tx by id



386
387
388
389
# File 'lib/cardano_wallet/shelley.rb', line 386

def get(wid, tx_id, query = {})
  query_formatted = query.empty? ? '' : Utils.to_query(query)
  self.class.get("/wallets/#{wid}/transactions/#{tx_id}#{query_formatted}")
end

#list(wid, query = {}) ⇒ Object

List all wallet’s transactions

Examples:

list(wid, {start: "2012-09-25T10:15:00Z", order: "descending"})

See Also:



396
397
398
399
# File 'lib/cardano_wallet/shelley.rb', line 396

def list(wid, query = {})
  query_formatted = query.empty? ? '' : Utils.to_query(query)
  self.class.get("/wallets/#{wid}/transactions#{query_formatted}")
end

#payment_fees(wid, payments, withdrawal = nil, metadata = nil, ttl = nil) ⇒ Object

Estimate fees for transaction

Examples:

payment_fees(wid, [{addr1: 1000000}, {addr2: 1000000}], {"1": "abc"}, ttl = 10)
payment_fees(wid, [{ "address": "addr1..",
                     "amount": { "quantity": 42000000, "unit": "lovelace" },
                     "assets": [{"policy_id": "pid", "asset_name": "name", "quantity": 0 } ] } ],
                     {"1": "abc"}, ttl = 10)

See Also:



443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
# File 'lib/cardano_wallet/shelley.rb', line 443

def payment_fees(wid, payments, withdrawal = nil,  = nil, ttl = nil)
  Utils.verify_param_is_array!(payments)
  payments_formatted = if payments.any? { |p| p.key?(:address) || p.key?('address') }
                         payments
                       else
                         Utils.format_payments(payments)
                       end

  payload = { payments: payments_formatted }

  payload[:withdrawal] = withdrawal if withdrawal
  payload[:metadata] =  if 
  payload[:time_to_live] = { quantity: ttl, unit: 'second' } if ttl

  self.class.post("/wallets/#{wid}/payment-fees",
                  body: payload.to_json,
                  headers: { 'Content-Type' => 'application/json' })
end

#sign(wid, passphrase, transaction, encoding = nil) ⇒ Object

Sign transaction

Parameters:

  • wid (String)

    source wallet id

  • passphrase (String)

    wallet’s passphrase

  • transaction (String)

    CBOR transaction data

  • encoding (String) (defaults to: nil)

    output encoding (“base16” or “base64”)

See Also:



362
363
364
365
366
367
368
369
370
371
# File 'lib/cardano_wallet/shelley.rb', line 362

def sign(wid, passphrase, transaction, encoding = nil)
  payload = {
    'passphrase' => passphrase,
    'transaction' => transaction
  }
  payload[:encoding] = encoding if encoding
  self.class.post("/wallets/#{wid}/transactions-sign",
                  body: payload.to_json,
                  headers: { 'Content-Type' => 'application/json' })
end

#submit(wid, transaction) ⇒ Object

Submit transaction

Parameters:

  • wid (String)

    source wallet id

  • transaction (String)

    CBOR transaction data

See Also:



377
378
379
380
381
382
# File 'lib/cardano_wallet/shelley.rb', line 377

def submit(wid, transaction)
  payload = { 'transaction' => transaction }
  self.class.post("/wallets/#{wid}/transactions-submit",
                  body: payload.to_json,
                  headers: { 'Content-Type' => 'application/json' })
end