|
| 1 | +// This is the official Ledger interface that is guaranteed to be backward compatible. |
| 2 | + |
| 3 | +// Amount of tokens, measured in 10^-8 of a token. |
| 4 | +type Tokens = record { |
| 5 | + e8s : nat64; |
| 6 | +}; |
| 7 | + |
| 8 | +// Number of nanoseconds from the UNIX epoch in UTC timezone. |
| 9 | +type TimeStamp = record { |
| 10 | + timestamp_nanos: nat64; |
| 11 | +}; |
| 12 | + |
| 13 | +// AccountIdentifier is a 32-byte array. |
| 14 | +// The first 4 bytes is big-endian encoding of a CRC32 checksum of the last 28 bytes. |
| 15 | +type AccountIdentifier = blob; |
| 16 | + |
| 17 | +// Subaccount is an arbitrary 32-byte byte array. |
| 18 | +// Ledger uses subaccounts to compute the source address, which enables one |
| 19 | +// principal to control multiple ledger accounts. |
| 20 | +type SubAccount = blob; |
| 21 | + |
| 22 | +// Sequence number of a block produced by the ledger. |
| 23 | +type BlockIndex = nat64; |
| 24 | + |
| 25 | +// An arbitrary number associated with a transaction. |
| 26 | +// The caller can set it in a `transfer` call as a correlation identifier. |
| 27 | +type Memo = nat64; |
| 28 | + |
| 29 | +// Arguments for the `transfer` call. |
| 30 | +type TransferArgs = record { |
| 31 | + // Transaction memo. |
| 32 | + // See comments for the `Memo` type. |
| 33 | + memo: Memo; |
| 34 | + // The amount that the caller wants to transfer to the destination address. |
| 35 | + amount: Tokens; |
| 36 | + // The amount that the caller pays for the transaction. |
| 37 | + // Must be 10000 e8s. |
| 38 | + fee: Tokens; |
| 39 | + // The subaccount from which the caller wants to transfer funds. |
| 40 | + // If null, the ledger uses the default (all zeros) subaccount to compute the source address. |
| 41 | + // See comments for the `SubAccount` type. |
| 42 | + from_subaccount: opt SubAccount; |
| 43 | + // The destination account. |
| 44 | + // If the transfer is successful, the balance of this address increases by `amount`. |
| 45 | + to: AccountIdentifier; |
| 46 | + // The point in time when the caller created this request. |
| 47 | + // If null, the ledger uses current IC time as the timestamp. |
| 48 | + created_at_time: opt TimeStamp; |
| 49 | +}; |
| 50 | + |
| 51 | +type TransferError = variant { |
| 52 | + // The fee that the caller specified in the transfer request was not the one that ledger expects. |
| 53 | + // The caller can change the transfer fee to the `expected_fee` and retry the request. |
| 54 | + BadFee : record { expected_fee : Tokens; }; |
| 55 | + // The account specified by the caller doesn't have enough funds. |
| 56 | + InsufficientFunds : record { balance: Tokens; }; |
| 57 | + // The request is too old. |
| 58 | + // The ledger only accepts requests created within 24 hours window. |
| 59 | + // This is a non-recoverable error. |
| 60 | + TxTooOld : record { allowed_window_nanos: nat64 }; |
| 61 | + // The caller specified `created_at_time` that is too far in future. |
| 62 | + // The caller can retry the request later. |
| 63 | + TxCreatedInFuture : null; |
| 64 | + // The ledger has already executed the request. |
| 65 | + // `duplicate_of` field is equal to the index of the block containing the original transaction. |
| 66 | + TxDuplicate : record { duplicate_of: BlockIndex; } |
| 67 | +}; |
| 68 | + |
| 69 | +type TransferResult = variant { |
| 70 | + Ok : BlockIndex; |
| 71 | + Err : TransferError; |
| 72 | +}; |
| 73 | + |
| 74 | +// Arguments for the `account_balance` call. |
| 75 | +type AccountBalanceArgs = record { |
| 76 | + account: AccountIdentifier; |
| 77 | +}; |
| 78 | + |
| 79 | +service : { |
| 80 | + // Transfers tokens from a subaccount of the caller to the destination address. |
| 81 | + // The source address is computed from the principal of the caller and the specified subaccount. |
| 82 | + // When successful, returns the index of the block containing the transaction. |
| 83 | + transfer : (TransferArgs) -> (TransferResult); |
| 84 | + |
| 85 | + // Returns the amount of Tokens on the specified account. |
| 86 | + account_balance : (AccountBalanceArgs) -> (Tokens) query; |
| 87 | +} |
0 commit comments