Class: CardanoWallet::Byron::Transactions

Inherits:
CardanoWallet::Base show all
Defined in:
lib/cardano_wallet/byron.rb

Overview

Byron transactions

Examples:

@cw = CardanoWallet.new
@cw.byron.transactions # API for Byron Transactions

See Also:

Instance Attribute Summary

Attributes inherited from CardanoWallet::Base

#opt

Instance Method Summary collapse

Methods inherited from CardanoWallet::Base

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

Constructor Details

This class inherits a constructor from CardanoWallet::Base

Instance Method Details

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

Construct transaction

Parameters:

  • wid (String)

    source wallet id

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

    full payments payload with assets

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

    mint object

  • validity_interval (Hash) (defaults to: nil)

    validity_interval object

See Also:



259
260
261
262
263
264
265
266
267
268
269
# File 'lib/cardano_wallet/byron.rb', line 259

def construct(wid, payments = nil,  = nil, mint = nil, validity_interval = nil)
  payload = {}
  payload[:payments] = payments if payments
  payload[:metadata] =  if 
  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

#create(wid, passphrase, payments) ⇒ Object

Create a transaction from the Byron wallet.

Examples:

@cw.byron.transactions.create(wid, passphrase, [{addr1: 1000000}, {addr2: 1000000}])
@cw.byron.transactions.create(wid, passphrase, [{ "address": "addr1..",
                           "amount": { "quantity": 42000000, "unit": "lovelace" },
                           "assets": [{"policy_id": "pid", "asset_name": "name", "quantity": 0 } ] } ])

Parameters:

  • wid (String)

    source wallet id

  • passphrase (String)

    source wallet’s passphrase

  • payments (Array of Hashes)

    addres, amount pair

See Also:



326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/cardano_wallet/byron.rb', line 326

def create(wid, passphrase, payments)
  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
  self.class.post("/byron-wallets/#{wid}/transactions",
                  body: { payments: payments_formatted,
                          passphrase: passphrase }.to_json,
                  headers: { 'Content-Type' => 'application/json' })
end

#forget(wid, txid) ⇒ Object

Forget a transaction.



361
362
363
# File 'lib/cardano_wallet/byron.rb', line 361

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

#get(wid, tx_id) ⇒ Object

Get tx by id



300
301
302
# File 'lib/cardano_wallet/byron.rb', line 300

def get(wid, tx_id)
  self.class.get("/byron-wallets/#{wid}/transactions/#{tx_id}")
end

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

List all Byron wallet’s transactions.

Examples:

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

See Also:



309
310
311
312
# File 'lib/cardano_wallet/byron.rb', line 309

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

#payment_fees(wid, payments) ⇒ Object

Estimate fees for transaction

Examples:

@cw.byron.transactions.payment_fees(wid, [{addr1: 1000000}, {addr2: 1000000}])
@cw.byron.transactions.payment_fees(wid, [{ "address": "addr1..",
                     "amount": { "quantity": 42000000, "unit": "lovelace" },
                     "assets": [{"policy_id": "pid", "asset_name": "name", "quantity": 0 } ] } ])

See Also:



347
348
349
350
351
352
353
354
355
356
357
# File 'lib/cardano_wallet/byron.rb', line 347

def payment_fees(wid, payments)
  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
  self.class.post("/byron-wallets/#{wid}/payment-fees",
                  body: { payments: payments_formatted }.to_json,
                  headers: { 'Content-Type' => 'application/json' })
end

#sign(wid, passphrase, transaction) ⇒ Object

Sign transaction

Parameters:

  • wid (String)

    source wallet id

  • passphrase (String)

    wallet’s passphrase

  • transaction (String)

    CBOR transaction data

See Also:



276
277
278
279
280
281
282
283
284
285
# File 'lib/cardano_wallet/byron.rb', line 276

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

#submit(wid, transaction) ⇒ Object

Submit transaction

Parameters:

  • wid (String)

    source wallet id

  • transaction (String)

    CBOR transaction data

See Also:



291
292
293
294
295
296
# File 'lib/cardano_wallet/byron.rb', line 291

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