@dfinity/ledger-icp
Version:
A library for interfacing with the ICP ledger on the Internet Computer.
3 lines (2 loc) • 4.08 kB
JavaScript
import{b as g,d as N}from"./chunk-CQ4GZJ2C.js";import{Canister as V,createServices as b,toNullable as F}from"@dfinity/utils";var A=({IDL:t})=>{let f=t.Record({ledger_id:t.Principal}),n=t.Record({max_results:t.Nat64,start:t.Opt(t.Nat64),account_identifier:t.Text}),e=t.Record({e8s:t.Nat64}),c=t.Record({timestamp_nanos:t.Nat64}),o=t.Variant({Approve:t.Record({fee:e,from:t.Text,allowance:e,expected_allowance:t.Opt(e),expires_at:t.Opt(c),spender:t.Text}),Burn:t.Record({from:t.Text,amount:e,spender:t.Opt(t.Text)}),Mint:t.Record({to:t.Text,amount:e}),Transfer:t.Record({to:t.Text,fee:e,from:t.Text,amount:e,spender:t.Opt(t.Text)})}),r=t.Record({memo:t.Nat64,icrc1_memo:t.Opt(t.Vec(t.Nat8)),operation:o,timestamp:t.Opt(c),created_at_time:t.Opt(c)}),d=t.Record({id:t.Nat64,transaction:r}),u=t.Record({balance:t.Nat64,transactions:t.Vec(d),oldest_tx_id:t.Opt(t.Nat64)}),p=t.Record({message:t.Text}),a=t.Variant({Ok:u,Err:p}),s=t.Record({owner:t.Principal,subaccount:t.Opt(t.Vec(t.Nat8))}),l=t.Record({max_results:t.Nat,start:t.Opt(t.Nat),account:s}),m=t.Record({start:t.Nat,length:t.Nat}),_=t.Record({blocks:t.Vec(t.Vec(t.Nat8)),chain_length:t.Nat64}),T=t.Record({url:t.Text,method:t.Text,body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text))}),x=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),status_code:t.Nat16}),R=t.Record({num_blocks_synced:t.Nat64});return t.Service({get_account_identifier_balance:t.Func([t.Text],[t.Nat64],[]),get_account_identifier_transactions:t.Func([n],[a],[]),get_account_transactions:t.Func([l],[a],[]),get_blocks:t.Func([m],[_],[]),http_request:t.Func([T],[x],[]),icrc1_balance_of:t.Func([s],[t.Nat64],[]),ledger_id:t.Func([],[t.Principal],[]),status:t.Func([],[R],[])})};var O=({IDL:t})=>{let f=t.Record({ledger_id:t.Principal}),n=t.Record({max_results:t.Nat64,start:t.Opt(t.Nat64),account_identifier:t.Text}),e=t.Record({e8s:t.Nat64}),c=t.Record({timestamp_nanos:t.Nat64}),o=t.Variant({Approve:t.Record({fee:e,from:t.Text,allowance:e,expected_allowance:t.Opt(e),expires_at:t.Opt(c),spender:t.Text}),Burn:t.Record({from:t.Text,amount:e,spender:t.Opt(t.Text)}),Mint:t.Record({to:t.Text,amount:e}),Transfer:t.Record({to:t.Text,fee:e,from:t.Text,amount:e,spender:t.Opt(t.Text)})}),r=t.Record({memo:t.Nat64,icrc1_memo:t.Opt(t.Vec(t.Nat8)),operation:o,timestamp:t.Opt(c),created_at_time:t.Opt(c)}),d=t.Record({id:t.Nat64,transaction:r}),u=t.Record({balance:t.Nat64,transactions:t.Vec(d),oldest_tx_id:t.Opt(t.Nat64)}),p=t.Record({message:t.Text}),a=t.Variant({Ok:u,Err:p}),s=t.Record({owner:t.Principal,subaccount:t.Opt(t.Vec(t.Nat8))}),l=t.Record({max_results:t.Nat,start:t.Opt(t.Nat),account:s}),m=t.Record({start:t.Nat,length:t.Nat}),_=t.Record({blocks:t.Vec(t.Vec(t.Nat8)),chain_length:t.Nat64}),T=t.Record({url:t.Text,method:t.Text,body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text))}),x=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),status_code:t.Nat16}),R=t.Record({num_blocks_synced:t.Nat64});return t.Service({get_account_identifier_balance:t.Func([t.Text],[t.Nat64],["query"]),get_account_identifier_transactions:t.Func([n],[a],["query"]),get_account_transactions:t.Func([l],[a],["query"]),get_blocks:t.Func([m],[_],["query"]),http_request:t.Func([T],[x],["query"]),icrc1_balance_of:t.Func([s],[t.Nat64],["query"]),ledger_id:t.Func([],[t.Principal],["query"]),status:t.Func([],[R],["query"])})};var i=class extends Error{};var y=class t extends V{constructor(){super(...arguments);this.accountBalance=({certified:n,accountIdentifier:e})=>this.caller({certified:n}).get_account_identifier_balance(N(e));this.getTransactions=async({certified:n,accountIdentifier:e,start:c,maxResults:o})=>{let r=await this.caller({certified:n}).get_account_identifier_transactions({account_identifier:N(e),start:F(c),max_results:o});if("Err"in r)throw new i(r.Err.message);return r.Ok}}static create({canisterId:n,...e}){let{service:c,certifiedService:o,canisterId:r}=b({options:{...e,canisterId:n??g},idlFactory:O,certifiedIdlFactory:A});return new t(r,c,o)}};export{y as a};
//# sourceMappingURL=chunk-OHHNCOLH.js.map