Class: IcAgent::Common::Ledger
- Inherits:
-
Object
- Object
- IcAgent::Common::Ledger
- Defined in:
- lib/ic_agent/common/ledger.rb
Constant Summary collapse
- CANISTER_ID =
'ryjl3-tyaaa-aaaaa-aaaba-cai'- DID_FILE =
"// This is the official Ledger interface that is guaranteed to be backward compatible.\n\n// Amount of tokens, measured in 10^-8 of a token.\ntype Tokens = record {\n e8s : nat64;\n};\n\n// Number of nanoseconds from the UNIX epoch in UTC timezone.\ntype TimeStamp = record {\n timestamp_nanos: nat64;\n};\n\n// AccountIdentifier is a 32-byte array.\n// The first 4 bytes is big-endian encoding of a CRC32 checksum of the last 28 bytes.\ntype AccountIdentifier = blob;\n\n// Subaccount is an arbitrary 32-byte byte array.\n// Ledger uses subaccounts to compute the source address, which enables one\n// principal to control multiple ledger accounts.\ntype SubAccount = blob;\n\n// Sequence number of a block produced by the ledger.\ntype BlockIndex = nat64;\n\n// An arbitrary number associated with a transaction.\n// The caller can set it in a `transfer` call as a correlation identifier.\ntype Memo = nat64;\n\n// Arguments for the `transfer` call.\ntype TransferArgs = record {\n memo: Memo;\n amount: Tokens;\n fee: Tokens;\n from_subaccount: opt SubAccount;\n to: AccountIdentifier;\n created_at_time: opt TimeStamp;\n};\n\ntype TransferError = variant {\n BadFee : record { expected_fee : Tokens; };\n InsufficientFunds : record { balance: Tokens; };\n TxTooOld : record { allowed_window_nanos: nat64 };\n TxCreatedInFuture : null;\n TxDuplicate : record { duplicate_of: BlockIndex; }\n};\n\ntype TransferResult = variant {\n Ok : BlockIndex;\n Err : TransferError;\n};\n\n// Arguments for the `account_balance` call.\ntype AccountBalanceArgs = record {\n account: AccountIdentifier;\n};\n\ntype TransferFeeArg = record {};\n\ntype TransferFee = record {\n transfer_fee: Tokens;\n};\n\ntype GetBlocksArgs = record {\n start : BlockIndex;\n length : nat64;\n};\n\ntype Operation = variant {\n Mint : record {\n to : AccountIdentifier;\n amount : Tokens;\n };\n Burn : record {\n from : AccountIdentifier;\n amount : Tokens;\n };\n Transfer : record {\n from : AccountIdentifier;\n to : AccountIdentifier;\n amount : Tokens;\n fee : Tokens;\n };\n};\n\ntype Transaction = record {\n memo : Memo;\n operation : opt Operation;\n created_at_time : TimeStamp;\n};\n\ntype Block = record {\n parent_hash : opt blob;\n transaction : Transaction;\n timestamp : TimeStamp;\n};\n\n// A prefix of the block range specified in the [GetBlocksArgs] request.\ntype BlockRange = record {\n blocks : vec Block;\n};\n\n// An error indicating that the arguments passed to [QueryArchiveFn] were invalid.\ntype QueryArchiveError = variant {\n BadFirstBlockIndex : record {\n requested_index : BlockIndex;\n first_valid_index : BlockIndex;\n };\n Other : record {\n error_code : nat64;\n error_message : text;\n };\n};\n\ntype QueryArchiveResult = variant {\n Ok : BlockRange;\n Err : QueryArchiveError;\n};\n\n// A function that is used for fetching archived ledger blocks.\ntype QueryArchiveFn = func (GetBlocksArgs) -> (QueryArchiveResult) query;\n\n// The result of a \"query_blocks\" call.\n//\n// The structure of the result is somewhat complicated because the main ledger canister might\n// not have all the blocks that the caller requested: One or more \"archive\" canisters might\n// store some of the requested blocks.\n//\n// Note: as of Q4 2021 when this interface is authored, the IC doesn't support making nested \n// query calls within a query call.\ntype QueryBlocksResponse = record {\n chain_length : nat64;\n certificate : opt blob;\n blocks : vec Block;\n first_block_index : BlockIndex;\n archived_blocks : vec record {\n start : BlockIndex;\n length : nat64;\n callback : QueryArchiveFn;\n };\n};\n\ntype Archive = record {\n canister_id: principal;\n};\n\ntype Archives = record {\n archives: vec Archive;\n};\n\nservice : {\n transfer : (TransferArgs) -> (TransferResult);\n account_balance : (AccountBalanceArgs) -> (Tokens) query;\n transfer_fee : (TransferFeeArg) -> (TransferFee) query;\n query_blocks : (GetBlocksArgs) -> (QueryBlocksResponse) query;\n symbol : () -> (record { symbol: text }) query;\n name : () -> (record { name: text }) query;\n decimals : () -> (record { decimals: nat32 }) query;\n archives : () -> (Archives) query;\n}\n"
Instance Attribute Summary collapse
-
#agent ⇒ Object
Returns the value of attribute agent.
-
#canister ⇒ Object
Returns the value of attribute canister.
-
#client ⇒ Object
Returns the value of attribute client.
-
#identity ⇒ Object
Returns the value of attribute identity.
Instance Method Summary collapse
-
#initialize(iden = nil) ⇒ Ledger
constructor
A new instance of Ledger.
Constructor Details
#initialize(iden = nil) ⇒ Ledger
Returns a new instance of Ledger.
169 170 171 172 173 174 |
# File 'lib/ic_agent/common/ledger.rb', line 169 def initialize(iden = nil) @identity = iden.nil? ? IcAgent::Identity.new : iden @client = IcAgent::Client.new @agent = IcAgent::Agent.new(@identity, @client) @canister = IcAgent::Canister.new(@agent, CANISTER_ID, DID_FILE) end |
Instance Attribute Details
#agent ⇒ Object
Returns the value of attribute agent.
167 168 169 |
# File 'lib/ic_agent/common/ledger.rb', line 167 def agent @agent end |
#canister ⇒ Object
Returns the value of attribute canister.
167 168 169 |
# File 'lib/ic_agent/common/ledger.rb', line 167 def canister @canister end |
#client ⇒ Object
Returns the value of attribute client.
167 168 169 |
# File 'lib/ic_agent/common/ledger.rb', line 167 def client @client end |
#identity ⇒ Object
Returns the value of attribute identity.
167 168 169 |
# File 'lib/ic_agent/common/ledger.rb', line 167 def identity @identity end |