@blockula/sdk 0.5.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +143 -13
- package/dist/describe.d.ts +3 -1
- package/dist/describe.js +93 -2
- package/dist/index.d.ts +602 -11
- package/dist/index.js +1080 -58
- package/dist/networks.d.ts +25 -0
- package/dist/networks.js +27 -0
- package/dist/payments.d.ts +83 -0
- package/dist/payments.js +240 -0
- package/dist/programs.d.ts +471 -0
- package/dist/programs.js +779 -0
- package/dist/proof.d.ts +44 -0
- package/dist/proof.js +62 -0
- package/dist/tx.d.ts +135 -0
- package/dist/tx.js +213 -0
- package/package.json +6 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { type SeanceClaimRef, type Action, type BaseFee, type ProposalKind, type Tx, type UnsignedTx } from "./tx.js";
|
|
1
|
+
import { type SeanceClaimRef, type Action, type BaseFee, type ProposalKind, type ProgramPolicy, type Tx, type UnsignedTx } from "./tx.js";
|
|
2
2
|
import { type ProofResponse, type ProvenRecord } from "./proof.js";
|
|
3
|
+
import { type ProgramCodeInfo, type ProgramCost, type ProgramFuel, type ProgramInfo, type ProgramInterfaceInfo, type ProgramParams, type ProgramReceipt, type ProgramViewResult } from "./programs.js";
|
|
4
|
+
import { type NetworkName } from "./networks.js";
|
|
3
5
|
export * from "./tx.js";
|
|
4
6
|
export * from "./proof.js";
|
|
5
7
|
export * from "./distribution.js";
|
|
6
8
|
export * from "./release.js";
|
|
7
9
|
export * from "./describe.js";
|
|
10
|
+
export * from "./networks.js";
|
|
11
|
+
export * from "./payments.js";
|
|
12
|
+
export * from "./programs.js";
|
|
8
13
|
export declare const DEFAULT_RPC = "http://localhost:7070";
|
|
9
14
|
/** Address prefixes: `boo` on mainnet (and dev chains), `tboo` on public testnets. */
|
|
10
15
|
export declare const KNOWN_PREFIXES: readonly ["boo", "tboo"];
|
|
@@ -21,7 +26,11 @@ export declare function keyId(publicKey: Uint8Array): string;
|
|
|
21
26
|
export declare function addressPrefix(s: string): string | undefined;
|
|
22
27
|
/** Whether `s` is an address: with any known prefix, or exactly `prefix` when given. */
|
|
23
28
|
export declare function isAddress(s: string, prefix?: string): boolean;
|
|
24
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* An amount of FANG: a decimal string ("1.5") or bigint drops (1 FANG = 10⁹ drops).
|
|
31
|
+
* A JS number is still accepted, but that form is deprecated and will be dropped: floats can't
|
|
32
|
+
* hold most decimal amounts exactly (`0.1 + 0.2`). Pass a string.
|
|
33
|
+
*/
|
|
25
34
|
export type Amount = string | number | bigint;
|
|
26
35
|
/** A `.boo` name as the chain stores it (node/src/types.rs `normalize_name`): lowercase, without the suffix. */
|
|
27
36
|
export declare function bareName(name: string): string;
|
|
@@ -202,7 +211,38 @@ export interface TxOptions {
|
|
|
202
211
|
tip?: string | number | bigint;
|
|
203
212
|
/** Blocks from now the tx stays valid (at most the chain's `max_tx_validity_blocks`, an hour of blocks). Default: the wallet's `validForBlocks` (600). */
|
|
204
213
|
validForBlocks?: number;
|
|
214
|
+
/**
|
|
215
|
+
* Room for the base fee to rise before the tx is included (TR-6): its `fee` becomes this many
|
|
216
|
+
* times the base fee `/api/fees` fixes for the next 17 blocks (`suggested`), plus the tip. Only
|
|
217
|
+
* the including block's base fee and the tip are charged, so headroom costs nothing; without it a
|
|
218
|
+
* tx queued behind full blocks for longer than that can stop covering the base fee and be
|
|
219
|
+
* dropped (with every later tx from the account). 1 to 100; default the wallet's `feeHeadroom` (1).
|
|
220
|
+
*/
|
|
221
|
+
feeHeadroom?: number;
|
|
222
|
+
/**
|
|
223
|
+
* The tx's `fee` outright (FANG, or bigint drops): the most it may be charged, base fee plus tip.
|
|
224
|
+
* At least what it costs at `suggested` now. Overrides `feeHeadroom`.
|
|
225
|
+
*/
|
|
226
|
+
maxFee?: Amount;
|
|
227
|
+
}
|
|
228
|
+
/** `Wallet.send`'s options. */
|
|
229
|
+
export interface SendOptions extends TxOptions {
|
|
230
|
+
/** Public, up to 256 bytes, written by the payer: an order or user id you issued. */
|
|
231
|
+
memo?: string;
|
|
232
|
+
/** Wait for it to finalize (default true); `false` returns as soon as a node admitted it. */
|
|
233
|
+
wait?: boolean;
|
|
234
|
+
/**
|
|
235
|
+
* Called with the signed tx and its id before it's submitted, in the wallet's queue (so parallel
|
|
236
|
+
* sends still get one nonce each): store both here, and every outcome is recoverable by
|
|
237
|
+
* resubmitting the same bytes (`client.post(tx)`). If it throws, nothing is submitted, the
|
|
238
|
+
* error is passed on, and the next tx takes the nonce.
|
|
239
|
+
*/
|
|
240
|
+
onSigned?: (tx: Tx, id: string) => void | Promise<void>;
|
|
205
241
|
}
|
|
242
|
+
/** The most `feeHeadroom` a tx may ask for: 100 × the base fee. */
|
|
243
|
+
export declare const MAX_FEE_HEADROOM = 100;
|
|
244
|
+
/** The least a payment that opens an account must carry: 0.01 FANG (node/src/types.rs `MIN_NEW_ACCOUNT`). */
|
|
245
|
+
export declare const MIN_NEW_ACCOUNT = 10000000n;
|
|
206
246
|
/** `Wallet.build`'s options: a tx's, plus the resolutions of names it carries as addresses. */
|
|
207
247
|
export interface BuildOptions extends TxOptions {
|
|
208
248
|
/** `Client.resolution`s of names in `action`'s address fields (refused on mainnet unless proven). */
|
|
@@ -246,7 +286,16 @@ export declare class Wallet {
|
|
|
246
286
|
tip: bigint;
|
|
247
287
|
/** Default validity (blocks from now) for this wallet's transactions. */
|
|
248
288
|
validForBlocks: number;
|
|
289
|
+
/** Default `feeHeadroom` for this wallet's transactions (1: none). See `TxOptions.feeHeadroom`. */
|
|
290
|
+
feeHeadroom: number;
|
|
249
291
|
private readonly secretKey;
|
|
292
|
+
/**
|
|
293
|
+
* This wallet's txs are signed and submitted one at a time, in nonce order (DEV-3): parallel
|
|
294
|
+
* `send`s from one wallet would otherwise read the same next nonce and all but one be refused.
|
|
295
|
+
*/
|
|
296
|
+
private queue;
|
|
297
|
+
/** The nonce after the last tx this wallet submitted, for one chain and account, and that tx. */
|
|
298
|
+
private cursor?;
|
|
250
299
|
private acting?;
|
|
251
300
|
/** How `actAs` found the account, when that was one node's unproven word (checked when signing on mainnet). */
|
|
252
301
|
private actingUnproven?;
|
|
@@ -319,6 +368,35 @@ export declare class Wallet {
|
|
|
319
368
|
* found that way (audit gap-7-1). Checked against the very status the tx is signed for.
|
|
320
369
|
*/
|
|
321
370
|
private buildChecked;
|
|
371
|
+
/**
|
|
372
|
+
* A tx's `fee`: the base fee at `suggested` for its size (and, for a program transaction, its
|
|
373
|
+
* fuel fee at the suggested rate: `fuelFee`), times the headroom, plus the tip; or `maxFee`
|
|
374
|
+
* outright, which must cover at least that base fee plus the tip.
|
|
375
|
+
*/
|
|
376
|
+
private feeFor;
|
|
377
|
+
/**
|
|
378
|
+
* The nonce for this wallet's next tx on chain/account `key`: the node's `next_nonce` (which
|
|
379
|
+
* counts the txs it holds), or one past the last tx this wallet submitted when that's higher
|
|
380
|
+
* and the tx may still run: still pending on its way through the network, or not yet counted
|
|
381
|
+
* by a node writing a block (DEV-3). A tx that was dropped, or can't run any more
|
|
382
|
+
* (`valid_until` passed), gives its nonce back: the node's word is used again. A nonce handed to
|
|
383
|
+
* a tx a node admitted is never handed out again while that tx may run.
|
|
384
|
+
*/
|
|
385
|
+
private nonceFor;
|
|
386
|
+
/** Runs `job` after every job queued before it (its outcome doesn't stop the next one). */
|
|
387
|
+
private enqueue;
|
|
388
|
+
/**
|
|
389
|
+
* Builds, signs and submits one tx in this wallet's queue (`enqueue`): one at a time, so each
|
|
390
|
+
* is admitted before the next is signed, in nonce order (DEV-3). Waits for it after leaving the
|
|
391
|
+
* queue, so parallel calls are only serialized for the moment it takes to sign and submit.
|
|
392
|
+
*
|
|
393
|
+
* What a failure does to the next nonce: refused by the node (a 4xx answer: it wasn't admitted),
|
|
394
|
+
* the nonce is used for the next tx, which can't be paid twice since only one tx per nonce ever
|
|
395
|
+
* runs; on "bad nonce" the same signed bytes are tried again once (a node writing a block can
|
|
396
|
+
* misjudge a correct nonce for a moment), then the node's next nonce is used. Anything else
|
|
397
|
+
* (a timeout, a 5xx, a broken connection) may have been admitted, so its nonce isn't reused.
|
|
398
|
+
*/
|
|
399
|
+
private submitQueued;
|
|
322
400
|
/**
|
|
323
401
|
* Send FANG to a `.boo` name or an address. `amount` is in FANG ("1.5") or bigint drops. A name
|
|
324
402
|
* is signed as its proven owner's address when the client has witnesses (who you checked is who
|
|
@@ -328,10 +406,63 @@ export declare class Wallet {
|
|
|
328
406
|
* from the height the node reported, and release it later, by when the name may have lapsed
|
|
329
407
|
* and been registered again (audit gap-7-1, review-r3-clients-2). See `Client.recipient`.
|
|
330
408
|
*/
|
|
331
|
-
send(to: string, amount:
|
|
409
|
+
send(to: string, amount: Amount, opts?: SendOptions): Promise<any>;
|
|
410
|
+
/**
|
|
411
|
+
* `send`, with the batch's retry policy. An amount of 0 is refused before anything is signed
|
|
412
|
+
* (DEV-14): it moves nothing and only pays a fee. A payment that opens an account must carry at
|
|
413
|
+
* least 0.01 FANG and burns `creation_fee` (0.1 FANG) from this account on top; the result of a
|
|
414
|
+
* finalized payment that did says so (`opened_account`, `creation_fee`), since its `summary` and
|
|
415
|
+
* `fee` don't (DEV-7).
|
|
416
|
+
*/
|
|
417
|
+
private pay;
|
|
418
|
+
/**
|
|
419
|
+
* Whether a payment to `address` would open its account, and what that burns from the payer
|
|
420
|
+
* (`/api/account`'s `exists` and `creation_fee`; on nodes without them, an account with no
|
|
421
|
+
* balance and no nonce counts as new). `undefined` when the node didn't say.
|
|
422
|
+
*/
|
|
423
|
+
private openingCost;
|
|
424
|
+
/**
|
|
425
|
+
* Whether finalized payment `tx` opened `address`'s account (it had none when the payment was
|
|
426
|
+
* signed): no other finalized tx naming it ran before this one. From its newest history, so a
|
|
427
|
+
* flood of more than 25 txs to a brand-new account within seconds can hide an earlier one.
|
|
428
|
+
*/
|
|
429
|
+
private opened;
|
|
430
|
+
/**
|
|
431
|
+
* What paying `amount` to `to` would cost this account, before anything is signed (DEV-7):
|
|
432
|
+
* - `fee`: the base fee for this payment's size at what `/api/fees` fixes for the next 17 blocks
|
|
433
|
+
* (`suggested`), plus the tip. On a chain that isn't busy, what it's charged;
|
|
434
|
+
* - `maxFee`: the most it can be charged (`fee`, or more with `feeHeadroom` / `maxFee`);
|
|
435
|
+
* - `creationFee`: burned from this account when the payment opens the recipient's account
|
|
436
|
+
* (0.1 FANG on chains with genesis defaults), on top of `amount`;
|
|
437
|
+
* - `total`: `amount + fee + creationFee`;
|
|
438
|
+
* - `transferableAfter`: what this account could still move afterwards, counting `maxFee`
|
|
439
|
+
* (negative: it can't pay this). Amounts are bigint drops; `display` has them as FANG text.
|
|
440
|
+
* `recipient` is how `to` gets signed (`Client.recipient`): show `recipient.how` before paying.
|
|
441
|
+
* Refuses (throws) a 0 amount, and less than 0.01 FANG to an account that doesn't exist yet.
|
|
442
|
+
*/
|
|
443
|
+
quote(to: string, amount: Amount, opts?: {
|
|
332
444
|
memo?: string;
|
|
445
|
+
} & TxOptions): Promise<Quote>;
|
|
446
|
+
/**
|
|
447
|
+
* Many payments from this account (TR-5), with at most `concurrency` (default 16, at most 64,
|
|
448
|
+
* the chain's limit of pending txs per sender) waiting to finalize at once. They're signed in
|
|
449
|
+
* turn, one nonce after the other. A node that answers 429 (rate limited) or "too many pending
|
|
450
|
+
* transactions" gets the same signed bytes again once it says to retry (`Retry-After`), for up
|
|
451
|
+
* to `patienceMs` (default 2 minutes); resubmitting the same bytes can't pay twice.
|
|
452
|
+
*
|
|
453
|
+
* Every payment gets a result, in order: `{ ok: true, tx }` or `{ ok: false, error }`. A refused
|
|
454
|
+
* payment (the node said no: insufficient balance, a bad name) used no nonce, and the rest go on.
|
|
455
|
+
* A payment that failed for another reason (`TxPendingError`, `TxFailedError` with `dropped`, a
|
|
456
|
+
* timeout) may still run: check it (`client.tx`) before paying it again, and note that when the
|
|
457
|
+
* chain drops a tx it drops every later one from the account too. `onSigned` is called with
|
|
458
|
+
* each signed tx before it's submitted, as with `send`.
|
|
459
|
+
*/
|
|
460
|
+
sendMany(payments: PaymentOrder[], opts?: {
|
|
461
|
+
concurrency?: number;
|
|
333
462
|
wait?: boolean;
|
|
334
|
-
|
|
463
|
+
patienceMs?: number;
|
|
464
|
+
onSigned?: SendOptions["onSigned"];
|
|
465
|
+
} & TxOptions): Promise<PaymentResult[]>;
|
|
335
466
|
registerName(name: string, opts?: {
|
|
336
467
|
wait?: boolean;
|
|
337
468
|
} & TxOptions): Promise<any>;
|
|
@@ -566,19 +697,222 @@ export declare class Wallet {
|
|
|
566
697
|
claimDistribution(distributionId: number, amount: Amount, proof: string[], opts?: TxOptions): Promise<any>;
|
|
567
698
|
/** Low-level (validator nodes do this automatically): a matured claim's PR was reverted by commit `revertSha`. */
|
|
568
699
|
attestRevert(claimId: number, revertSha: string, opts?: TxOptions): Promise<any>;
|
|
700
|
+
/** The chain's fuel prices, with programs required to be on (`ProgramsOffError`) and to admit this kind of transaction now. */
|
|
701
|
+
private programsFor;
|
|
702
|
+
/** Waits (up to `waitMs`) for the node's head to pass `height`: what block `height` stored is usable from the next one (§2.1). */
|
|
703
|
+
private waitPast;
|
|
704
|
+
/**
|
|
705
|
+
* Runs what follows a transaction that was submitted and is final, saying so if it fails: `what` names
|
|
706
|
+
* the transaction (its id, and what it made), which was sent and ran, so the failure is of the receipt,
|
|
707
|
+
* the wait or the read after it, and the transaction must not be sent again. The typed error stays
|
|
708
|
+
* as `cause`; its reason is quoted stripped of hidden characters (it may hold a node's text). `what` may be a function
|
|
709
|
+
* so the name can grow as `run` learns more (the address a create made).
|
|
710
|
+
*/
|
|
711
|
+
private finalThen;
|
|
712
|
+
/**
|
|
713
|
+
* Waits (up to `waitMs`) until `read` finds what it names (`null`: not there yet) stored in a block
|
|
714
|
+
* before the node's head, which is when it's usable (§2.1: a create, or a call, signed earlier is
|
|
715
|
+
* refused by the mempool). Says what was waited for if it never is.
|
|
716
|
+
*/
|
|
717
|
+
private waitUsable;
|
|
718
|
+
/** A program as a call needs it: usable (stored in an earlier block), its digest recomputed from its own record, and proven against the client's witnesses when it has some. */
|
|
719
|
+
private programForCall;
|
|
720
|
+
/**
|
|
721
|
+
* The bindings of a transaction (`ProgramBindingInput`s): each program read (usable, checked, proven
|
|
722
|
+
* with witnesses), its version digest filled with the version in force now when none is given (never
|
|
723
|
+
* "any version", 64 zeros, unless asked: `ANY_PROGRAM_VERSION`), and its code added to `declared`,
|
|
724
|
+
* which load fuel is counted on.
|
|
725
|
+
*/
|
|
726
|
+
private resolveBindings;
|
|
727
|
+
/**
|
|
728
|
+
* Signs and submits a program transaction (reserving `reservation` fuel: its fee is priced with it),
|
|
729
|
+
* waits for it, checks its receipt (programs.ts `checkReceipt`) and returns it with what it cost.
|
|
730
|
+
* One that ran and failed throws `ProgramFailedError` (its fee was charged; `storageLimit` names
|
|
731
|
+
* the limit it signed, for the hint a `storage_limit` trap needs).
|
|
732
|
+
*
|
|
733
|
+
* Once the transaction is submitted and the node reports it final, **every failure says so**
|
|
734
|
+
* (`finalThen`): a receipt or answer that doesn't check isn't "nothing happened, ask another node",
|
|
735
|
+
* since the transaction ran, and a payable call sent again pays twice. The typed error is the `cause`.
|
|
736
|
+
*/
|
|
737
|
+
private sendProgram;
|
|
738
|
+
/**
|
|
739
|
+
* Uploads a program's code (WebAssembly 1.0) and its interface (format 1: `blockula program interface
|
|
740
|
+
* encode`, or the `.iface` files beside the guests), bonding a storage deposit for each that isn't
|
|
741
|
+
* stored yet: the deposit at today's price (`programUploadDeposit`), which v0 never gives back. `storageLimit`
|
|
742
|
+
* (FANG, default that deposit plus 10%) is the most the upload may bond; below the deposit it's
|
|
743
|
+
* refused before signing, as the upload would fail and still be charged. Fuel is priced at the
|
|
744
|
+
* node's suggested rate. Resolves once the upload is final **and the block after it has been sealed**,
|
|
745
|
+
* when the code is usable (a create signed sooner is refused, §2.1), with its receipt and what it
|
|
746
|
+
* cost: the fee, and the deposit, which `receipt.facts.outside_vm` holds apart from the VM's diff.
|
|
747
|
+
*/
|
|
748
|
+
uploadCode(wasm: Uint8Array | string, iface: Uint8Array | string, opts?: ProgramTxOptions & {
|
|
749
|
+
storageLimit?: Amount;
|
|
750
|
+
}): Promise<UploadedCode>;
|
|
751
|
+
/**
|
|
752
|
+
* Creates a program from stored code and interface (`uploadCode`'s hashes), at the address made from
|
|
753
|
+
* this account and the transaction's nonce, which is returned **only once the create has applied**
|
|
754
|
+
* and the block after it has been sealed (the program is then usable), never predicted ahead of it:
|
|
755
|
+
* FANG sent to a program's address before its create is final is stranded for good if the create
|
|
756
|
+
* fails (§2.3). It first waits for the code and interface to be usable (an upload a block ago).
|
|
757
|
+
*
|
|
758
|
+
* `init` runs the interface's `Init` method with its `input` and `value`, present exactly when the
|
|
759
|
+
* interface declares one; it runs under `fuelLimit` (default `program_max_tx_fuel`, 0 without `init`).
|
|
760
|
+
* `storageLimit` (FANG) is the most the record's deposit and what the initializer's writes bond may
|
|
761
|
+
* be: default the record's deposit plus 10%, which a program whose initializer writes needs more than.
|
|
762
|
+
* `authority` (an address, never a name) may upgrade it once a protocol version adds upgrades, with
|
|
763
|
+
* `delayBlocks` of notice (default and least: `program_min_upgrade_delay_blocks`) and an upgrade
|
|
764
|
+
* `policy`; without one the program is immutable. `bindings` are programs the initializer may reach.
|
|
765
|
+
* The receipt's `outside_vm` holds the record deposit and the account creation fee the create burns
|
|
766
|
+
* when the program's address held no account yet.
|
|
767
|
+
*/
|
|
768
|
+
createProgram(opts: CreateProgramOptions): Promise<CreatedProgram>;
|
|
769
|
+
/**
|
|
770
|
+
* Calls programs: 1 to 8 calls run in order, all or nothing, sharing `fuelLimit` (default
|
|
771
|
+
* `program_max_tx_fuel`) and `storageLimit` (FANG): **the default is 0, which consents to no new
|
|
772
|
+
* storage**, so a call whose writes bond a deposit traps `storage_limit` and still pays its fee
|
|
773
|
+
* (`ProgramFailedError` says so): pass a limit for any method that writes.
|
|
774
|
+
*
|
|
775
|
+
* Each call binds the `versionDigest` of the program it's calling: when you pass the digest you
|
|
776
|
+
* showed the user (`ProgramCallInput.versionDigest`) the call is refused if the program's code,
|
|
777
|
+
* interface or version isn't the one that digest names; without it, it's recomputed from the
|
|
778
|
+
* program's record (proven against the client's witnesses when it has any), never taken from the
|
|
779
|
+
* node's `version_digest`. Fuel is priced at the node's suggested rate on what's reserved (fuel to
|
|
780
|
+
* run, plus the load of the code the calls and `bindings` declare) and refused when no block
|
|
781
|
+
* could carry it (`FuelReservationError`). Waits for each program to be usable (created a block ago).
|
|
782
|
+
* The receipt's `claims` are what the programs say happened: the chain checks none of it.
|
|
783
|
+
*/
|
|
784
|
+
callProgram(calls: ProgramCallInput[], opts?: ProgramCallOptions): Promise<ProgramTxResult>;
|
|
785
|
+
/**
|
|
786
|
+
* One call: `program`'s `method` (a `call` method of its interface; read a `view` with
|
|
787
|
+
* `client.view`) with `input` (bytes, or lowercase hex) and `value` FANG attached (only to a
|
|
788
|
+
* payable method). It reads the program first, so a method its interface doesn't have, a view,
|
|
789
|
+
* an initializer, or FANG sent to a method that isn't payable is refused before anything is signed
|
|
790
|
+
* (the chain refuses them too, and charges the fee), and signs its `version_digest`: see `callProgram`,
|
|
791
|
+
* whose options it takes, including the 0 default of `storageLimit`.
|
|
792
|
+
*/
|
|
793
|
+
call(program: string, method: string, input?: Uint8Array | string, opts?: ProgramCallOptions & {
|
|
794
|
+
value?: Amount;
|
|
795
|
+
versionDigest?: string;
|
|
796
|
+
}): Promise<ProgramTxResult>;
|
|
797
|
+
/**
|
|
798
|
+
* For a validator: signs a vote to pause programs (tag 69), from the validator's own account with
|
|
799
|
+
* its key (build the wallet from `validator.key`'s seed and `actAs` nothing: it signs as itself).
|
|
800
|
+
* Programs pause from the block after f + 1 of the epoch's validators have signed, for days, with
|
|
801
|
+
* no undo, so check `client.params()`' `programs` section (the live `votes`, `pause_signed` and
|
|
802
|
+
* `fix_pending`) first, or use `blockula program pause`, which does.
|
|
803
|
+
*
|
|
804
|
+
* It signs and lets the chain's admission decide: a signature the chain refuses (this validator
|
|
805
|
+
* signed one recently, or has a live vote of its own, or isn't in the active set) is an `ApiError`
|
|
806
|
+
* 400 and is never charged. It reserves no fuel and prices none, so its fee is a plain
|
|
807
|
+
* transaction's; it only needs programs to have been switched on (`/api/fees` has a `fuel` section:
|
|
808
|
+
* `ProgramsOffError` otherwise), not any fuel schedule this SDK knows, since a pause must not depend on one.
|
|
809
|
+
*/
|
|
810
|
+
programsPause(opts?: TxOptions & {
|
|
811
|
+
onSigned?: SendOptions["onSigned"];
|
|
812
|
+
}): Promise<any>;
|
|
569
813
|
/** This account's shares in a validator's pool, for `"all"`; anything else is parsed and checked. */
|
|
570
814
|
private sharesOf;
|
|
571
815
|
/** A proposal kind with its accounts as `Client.recipient` signs them (the chain resolves names when the proposal is made). */
|
|
572
816
|
private resolveKind;
|
|
817
|
+
/**
|
|
818
|
+
* Everything this account holds, as FANG text ("12.5 FANG"), locked or not: `balances()` says
|
|
819
|
+
* what it can pay. "0 FANG" only for an account that doesn't exist yet; anything else that goes
|
|
820
|
+
* wrong (the node is down or rate limited, a timeout, another chain) throws (DEV-2), so a
|
|
821
|
+
* failure never reads as an empty account.
|
|
822
|
+
*/
|
|
573
823
|
balance(): Promise<string>;
|
|
824
|
+
/**
|
|
825
|
+
* This account's balances, in bigint drops (DEV-2):
|
|
826
|
+
* - `balance`: everything it holds;
|
|
827
|
+
* - `transferable`: what it can pay or send now, fees and tips included: the "can pay" number;
|
|
828
|
+
* - `locked`: what vesting and vote locks hold (their `until` is in `client.account(…).locks`).
|
|
829
|
+
* Staked FANG isn't in `balance` (see `client.staking`). `exists` is false for an account the
|
|
830
|
+
* chain hasn't opened yet (all zeros). Errors propagate, like `balance()`.
|
|
831
|
+
*/
|
|
832
|
+
balances(): Promise<Balances>;
|
|
574
833
|
/** Dev/test chains only: drip 100 FANG to this wallet. */
|
|
575
834
|
faucet(wait?: boolean): Promise<any>;
|
|
576
835
|
}
|
|
577
|
-
/**
|
|
836
|
+
/**
|
|
837
|
+
* An error response from a Blockula node. `status` is the HTTP status (429 = rate limited);
|
|
838
|
+
* `retryAfterMs`, when the node said how long to wait (`Retry-After`, or "try again in N minutes").
|
|
839
|
+
*/
|
|
578
840
|
export declare class ApiError extends Error {
|
|
579
841
|
readonly status: number;
|
|
580
|
-
|
|
842
|
+
readonly retryAfterMs?: number | undefined;
|
|
843
|
+
constructor(status: number, message: string, retryAfterMs?: number | undefined);
|
|
581
844
|
}
|
|
845
|
+
/**
|
|
846
|
+
* The node says it's on blockula-1, and this client isn't pinned to that chain (DEV-1). Nothing
|
|
847
|
+
* was signed. A client signs there only with a `chainId: "blockula-1"` pin.
|
|
848
|
+
*/
|
|
849
|
+
export declare class MainnetNotAllowedError extends Error {
|
|
850
|
+
readonly rpc: string;
|
|
851
|
+
constructor(rpc: string);
|
|
852
|
+
}
|
|
853
|
+
/** The most txs a node holds pending from one sender (node/src/chain.rs `MAX_PENDING_PER_SENDER`). */
|
|
854
|
+
export declare const MAX_PENDING_PER_SENDER = 64;
|
|
855
|
+
/** `Wallet.balances()`: an account's balances in bigint drops, and as FANG text. */
|
|
856
|
+
export interface Balances {
|
|
857
|
+
/** Everything the account holds (staked FANG isn't in it). */
|
|
858
|
+
balance: bigint;
|
|
859
|
+
/** What it can pay or send now, fees included: the "can pay" number. */
|
|
860
|
+
transferable: bigint;
|
|
861
|
+
/** What vesting and vote locks hold. */
|
|
862
|
+
locked: bigint;
|
|
863
|
+
/** Whether the chain has opened this account yet. */
|
|
864
|
+
exists: boolean;
|
|
865
|
+
display: {
|
|
866
|
+
balance: string;
|
|
867
|
+
transferable: string;
|
|
868
|
+
locked: string;
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
/** `Wallet.quote()`: what a payment would cost, in bigint drops (see `quote`). */
|
|
872
|
+
export interface Quote {
|
|
873
|
+
amount: bigint;
|
|
874
|
+
/** The base fee at `suggested` for its size, plus the tip. */
|
|
875
|
+
fee: bigint;
|
|
876
|
+
/** The most it can be charged (its `fee` field). */
|
|
877
|
+
maxFee: bigint;
|
|
878
|
+
/** Burned from the payer when the payment opens the recipient's account; 0 otherwise. */
|
|
879
|
+
creationFee: bigint;
|
|
880
|
+
/** amount + fee + creationFee. */
|
|
881
|
+
total: bigint;
|
|
882
|
+
/** What the payer could still move afterwards, counting `maxFee`; negative when it can't pay. */
|
|
883
|
+
transferableAfter: bigint;
|
|
884
|
+
enough: boolean;
|
|
885
|
+
/** The recipient has no account yet: this payment opens it. */
|
|
886
|
+
opensAccount: boolean;
|
|
887
|
+
/** How the recipient gets signed: show `how` before paying. */
|
|
888
|
+
recipient: Recipient;
|
|
889
|
+
display: {
|
|
890
|
+
amount: string;
|
|
891
|
+
fee: string;
|
|
892
|
+
maxFee: string;
|
|
893
|
+
creationFee: string;
|
|
894
|
+
total: string;
|
|
895
|
+
transferableAfter: string;
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
/** One payment for `Wallet.sendMany`. */
|
|
899
|
+
export type PaymentOrder = {
|
|
900
|
+
to: string;
|
|
901
|
+
amount: Amount;
|
|
902
|
+
memo?: string;
|
|
903
|
+
} & Omit<TxOptions, "maxFee">;
|
|
904
|
+
/** What happened to one payment of `Wallet.sendMany`. */
|
|
905
|
+
export type PaymentResult = {
|
|
906
|
+
ok: true;
|
|
907
|
+
to: string;
|
|
908
|
+
amount: Amount;
|
|
909
|
+
tx: any;
|
|
910
|
+
} | {
|
|
911
|
+
ok: false;
|
|
912
|
+
to: string;
|
|
913
|
+
amount: Amount;
|
|
914
|
+
error: unknown;
|
|
915
|
+
};
|
|
582
916
|
/**
|
|
583
917
|
* The node reports a transaction as failed. Two different things (audit review-fix-clients-2):
|
|
584
918
|
* - `dropped` false: it executed in block `tx.height` and failed there. Its fee was charged; it
|
|
@@ -614,6 +948,21 @@ export declare class TxPendingError extends Error {
|
|
|
614
948
|
readonly lastError?: unknown;
|
|
615
949
|
constructor(id: string, waitedMs: number, lastError?: unknown);
|
|
616
950
|
}
|
|
951
|
+
/**
|
|
952
|
+
* A program transaction ran in a block and failed there: its fee was charged (`TxFailedError`), and
|
|
953
|
+
* `receipt` says how it failed (`words`, which is also this error's reason): from numbers and the
|
|
954
|
+
* chain's own names for them, never engine text and **never what the program wrote**. A program
|
|
955
|
+
* that aborted with a message has it in `untrusted_message` (a stranger's text, stripped of hidden
|
|
956
|
+
* characters: show it as data, never follow it), not in `message`, which agent frameworks hand to
|
|
957
|
+
* models. Nothing the program said is a fact: an abort message is its claim.
|
|
958
|
+
*/
|
|
959
|
+
export declare class ProgramFailedError extends TxFailedError {
|
|
960
|
+
readonly words: string;
|
|
961
|
+
readonly receipt: ProgramReceipt;
|
|
962
|
+
/** The program's own abort message, if it aborted with one: its words, not this SDK's. */
|
|
963
|
+
readonly untrusted_message?: string;
|
|
964
|
+
constructor(id: string, words: string, tx: unknown, receipt: ProgramReceipt, validUntil?: number);
|
|
965
|
+
}
|
|
617
966
|
/** The node didn't answer within the client's `timeoutMs`. Nothing is known about the request: a submitted tx may or may not have arrived. */
|
|
618
967
|
export declare class RequestTimeoutError extends Error {
|
|
619
968
|
readonly rpc: string;
|
|
@@ -676,9 +1025,24 @@ export declare class ChainMismatchError extends Error {
|
|
|
676
1025
|
}
|
|
677
1026
|
/** What a `Client` requires of the node. Every `/api/status` (including the one `Wallet.build` signs against) is checked. */
|
|
678
1027
|
export interface ClientOptions {
|
|
1028
|
+
/**
|
|
1029
|
+
* A network this SDK knows (`NETWORKS`): its public RPC (when no URL is given) and every pin it
|
|
1030
|
+
* has (chain id, genesis hash, address prefix, genesis clock), set up front. Pins you pass too
|
|
1031
|
+
* must agree with it.
|
|
1032
|
+
*/
|
|
1033
|
+
network?: NetworkName;
|
|
1034
|
+
/**
|
|
1035
|
+
* Submit txs in their wire form (`txBytes`, `application/octet-stream`): about half the bytes
|
|
1036
|
+
* of JSON. Off by default: the JSON form is refused outright when it has a field the node doesn't
|
|
1037
|
+
* know (422), where the wire form leaves such a field out.
|
|
1038
|
+
*/
|
|
1039
|
+
wireTxs?: boolean;
|
|
679
1040
|
/** The address prefix you expect (`boo` or `tboo`). */
|
|
680
1041
|
prefix?: string;
|
|
681
|
-
/**
|
|
1042
|
+
/**
|
|
1043
|
+
* The chain id the node must report (e.g. `blockula-testnet-2`). Wallets sign on `blockula-1`
|
|
1044
|
+
* only through a client pinned to it (`MainnetNotAllowedError`).
|
|
1045
|
+
*/
|
|
682
1046
|
chainId?: string;
|
|
683
1047
|
/** The genesis hash (hex) the node must report. */
|
|
684
1048
|
genesisHash?: string;
|
|
@@ -772,12 +1136,104 @@ export interface ProvenOptions {
|
|
|
772
1136
|
/** How many blocks the proof may be behind the newest head seen (default `DEFAULT_MAX_PROOF_LAG_BLOCKS`). */
|
|
773
1137
|
maxLagBlocks?: number;
|
|
774
1138
|
}
|
|
1139
|
+
/** Options of a program transaction (`Wallet.uploadCode`, `createProgram`, `callProgram`, `call`): a tx's, and how long to wait. */
|
|
1140
|
+
export interface ProgramTxOptions extends TxOptions {
|
|
1141
|
+
/** Called with the signed tx and its id before it's submitted (as `SendOptions.onSigned`): store them, and every outcome is recoverable. */
|
|
1142
|
+
onSigned?: SendOptions["onSigned"];
|
|
1143
|
+
/** How long to wait (ms) for what the transaction needs to be usable, and for the block after its own (default 60 s). */
|
|
1144
|
+
waitMs?: number;
|
|
1145
|
+
}
|
|
1146
|
+
/** What `callProgram` and `call` take beyond a tx's options. */
|
|
1147
|
+
export interface ProgramCallOptions extends ProgramTxOptions {
|
|
1148
|
+
/** Fuel to run the calls, at most `program_max_tx_fuel` (default that). Reserved fuel is paid for and never refunded. */
|
|
1149
|
+
fuelLimit?: number;
|
|
1150
|
+
/** The most the calls' storage deposits may bond (FANG). Default 0: no new storage; a method that writes needs a limit. */
|
|
1151
|
+
storageLimit?: Amount;
|
|
1152
|
+
/** Programs the calls may reach besides their own. */
|
|
1153
|
+
bindings?: ProgramBindingInput[];
|
|
1154
|
+
}
|
|
1155
|
+
/** A program the transaction may reach: by address, at the version digest given, or the version in force now when none is (`ANY_PROGRAM_VERSION` for any). */
|
|
1156
|
+
export interface ProgramBindingInput {
|
|
1157
|
+
program: string;
|
|
1158
|
+
versionDigest?: string;
|
|
1159
|
+
}
|
|
1160
|
+
/** One call of `callProgram`. */
|
|
1161
|
+
export interface ProgramCallInput {
|
|
1162
|
+
/** The program's address, never a name. */
|
|
1163
|
+
program: string;
|
|
1164
|
+
/** A `call` method of its interface. */
|
|
1165
|
+
method: string;
|
|
1166
|
+
/** What the method reads: bytes, or lowercase hex. Default none. */
|
|
1167
|
+
input?: Uint8Array | string;
|
|
1168
|
+
/** FANG sent with the call (only to a payable method). */
|
|
1169
|
+
value?: Amount;
|
|
1170
|
+
/** The version digest the user was shown for this program: the call is refused if the program isn't the one it names. */
|
|
1171
|
+
versionDigest?: string;
|
|
1172
|
+
}
|
|
1173
|
+
/** What a finalized program transaction gave: the node's answer, its checked receipt, and what it cost its signer. */
|
|
1174
|
+
export interface ProgramTxResult {
|
|
1175
|
+
tx: any;
|
|
1176
|
+
receipt: ProgramReceipt;
|
|
1177
|
+
cost: ProgramCost;
|
|
1178
|
+
}
|
|
1179
|
+
/** `Wallet.uploadCode`'s result. */
|
|
1180
|
+
export interface UploadedCode extends ProgramTxResult {
|
|
1181
|
+
wasmHash: string;
|
|
1182
|
+
interfaceHash: string;
|
|
1183
|
+
/** What this upload bonded (drops): 0 when both were stored already. */
|
|
1184
|
+
deposit: bigint;
|
|
1185
|
+
}
|
|
1186
|
+
/** What `Wallet.createProgram` takes. */
|
|
1187
|
+
export interface CreateProgramOptions extends ProgramTxOptions {
|
|
1188
|
+
/** The stored code's hash and the stored interface's (`uploadCode` returns them). */
|
|
1189
|
+
wasmHash: string;
|
|
1190
|
+
interfaceHash: string;
|
|
1191
|
+
/** Run the interface's `Init` method as the program is created (present exactly when the interface has one). */
|
|
1192
|
+
init?: {
|
|
1193
|
+
method: string;
|
|
1194
|
+
input?: Uint8Array | string;
|
|
1195
|
+
value?: Amount;
|
|
1196
|
+
};
|
|
1197
|
+
/** Fuel for the initializer, at most `program_max_tx_fuel` (default that). */
|
|
1198
|
+
fuelLimit?: number;
|
|
1199
|
+
/** The most the record's deposit and the initializer's writes may bond (FANG; default the record's deposit plus 10%). */
|
|
1200
|
+
storageLimit?: Amount;
|
|
1201
|
+
bindings?: ProgramBindingInput[];
|
|
1202
|
+
/** An account (an address) that may upgrade the program once upgrades exist; without it the program is immutable. */
|
|
1203
|
+
authority?: string;
|
|
1204
|
+
delayBlocks?: number;
|
|
1205
|
+
policy?: ProgramPolicy;
|
|
1206
|
+
/** The program takes plain transfers to its address. */
|
|
1207
|
+
acceptsTransfers?: boolean;
|
|
1208
|
+
}
|
|
1209
|
+
/** `Wallet.createProgram`'s result: the program's address, only once the create has applied. */
|
|
1210
|
+
export interface CreatedProgram extends ProgramTxResult {
|
|
1211
|
+
address: string;
|
|
1212
|
+
/** The program as the node reads it a block after the create. */
|
|
1213
|
+
program: ProgramInfo;
|
|
1214
|
+
}
|
|
775
1215
|
/** A record proven against a state root, and the newest head height that root was checked against. */
|
|
776
1216
|
export type ProvenRead = ProvenRecord & {
|
|
777
1217
|
head: number;
|
|
778
1218
|
};
|
|
1219
|
+
/** A page of an account's history (`Client.history`), newest first. */
|
|
1220
|
+
export interface HistoryPage {
|
|
1221
|
+
/**
|
|
1222
|
+
* Finalized txs sent by the account or naming it, as `/api/tx` shows them (`to` is
|
|
1223
|
+
* `{ address, name }`). Pending ones are in `client.account(id).recent_txs`.
|
|
1224
|
+
*/
|
|
1225
|
+
txs: any[];
|
|
1226
|
+
/** The cursor of the next (older) page, for `before`; `null` at the end. */
|
|
1227
|
+
next: string | null;
|
|
1228
|
+
/** The first block the node holds: nothing older is in its history. */
|
|
1229
|
+
history_from?: number;
|
|
1230
|
+
/**
|
|
1231
|
+
* False on a node without paged history (`/api/account/{id}/txs`): `txs` is then `/api/account`'s
|
|
1232
|
+
* `recent_txs` (its pending txs and the newest 25 finalized ones), and there's no `next`.
|
|
1233
|
+
*/
|
|
1234
|
+
paged: boolean;
|
|
1235
|
+
}
|
|
779
1236
|
export declare class Client {
|
|
780
|
-
readonly rpc: string;
|
|
781
1237
|
/** The chain's address prefix: given, learned from `/api/status`, or `boo` until then. */
|
|
782
1238
|
prefix: string;
|
|
783
1239
|
private prefixKnown;
|
|
@@ -796,8 +1252,27 @@ export declare class Client {
|
|
|
796
1252
|
createdAtMs: number;
|
|
797
1253
|
blockTimeMs: number;
|
|
798
1254
|
};
|
|
799
|
-
/**
|
|
800
|
-
|
|
1255
|
+
/** The node's URL. */
|
|
1256
|
+
readonly rpc: string;
|
|
1257
|
+
/** The network this client was made for (`ClientOptions.network`), if any. */
|
|
1258
|
+
readonly network?: NetworkName;
|
|
1259
|
+
/** See `ClientOptions.wireTxs`. */
|
|
1260
|
+
readonly wireTxs: boolean;
|
|
1261
|
+
/** The public testnet (`NETWORKS.testnet`), every pin set: `Client.testnet({ witnesses })`, or pass your own node's URL as `rpc`. */
|
|
1262
|
+
static testnet(opts?: Omit<ClientOptions, "network"> & {
|
|
1263
|
+
rpc?: string;
|
|
1264
|
+
}): Client;
|
|
1265
|
+
/** A `blockula dev` chain on this machine (`NETWORKS.local`). */
|
|
1266
|
+
static local(opts?: Omit<ClientOptions, "network"> & {
|
|
1267
|
+
rpc?: string;
|
|
1268
|
+
}): Client;
|
|
1269
|
+
/**
|
|
1270
|
+
* `new Client(rpc, opts)`, `new Client({ network: "testnet" })` (the network's public RPC), or
|
|
1271
|
+
* `new Client(rpc, { network })` (your own node, held to that network's pins). The pins
|
|
1272
|
+
* (`opts`, and the network's) are checked on every status: a node reporting another prefix,
|
|
1273
|
+
* chain id or genesis hash is refused with `ChainMismatchError`.
|
|
1274
|
+
*/
|
|
1275
|
+
constructor(rpc?: string | ClientOptions, options?: ClientOptions);
|
|
801
1276
|
/**
|
|
802
1277
|
* Refuses (`HeightAheadError`, before anything is signed) a height a tx's validity window would
|
|
803
1278
|
* count from that this client has reason to think the chain hasn't reached: more than
|
|
@@ -810,12 +1285,44 @@ export declare class Client {
|
|
|
810
1285
|
* Without witnesses or a genesis clock, the height is the node's word.
|
|
811
1286
|
*/
|
|
812
1287
|
checkSigningHeight(height: number): Promise<void>;
|
|
1288
|
+
/**
|
|
1289
|
+
* Refuses (`HeightAheadError`) a height the chain can't have reached by this machine's clock and
|
|
1290
|
+
* the `genesisClock` this client was given: the clock half of `checkSigningHeight`, for heights a
|
|
1291
|
+
* node reports that aren't signed against (a read's, a wait's). Without a `genesisClock` the
|
|
1292
|
+
* height is the node's word.
|
|
1293
|
+
*/
|
|
1294
|
+
checkHeightClock(height: number): void;
|
|
813
1295
|
/** The chain's address prefix, asking the node once if it isn't known yet. */
|
|
814
1296
|
addressPrefix(): Promise<string>;
|
|
1297
|
+
/**
|
|
1298
|
+
* Throws `MainnetNotAllowedError` for a status on blockula-1 unless this client is pinned to that
|
|
1299
|
+
* chain (`chainPin`). Wallets call it with the very status each tx is signed for (DEV-1).
|
|
1300
|
+
*/
|
|
1301
|
+
checkMainnetPin(chainId: unknown): void;
|
|
1302
|
+
/** The chain id this client is pinned to (`ClientOptions.chainId`), if any. A client that pins the chain itself reports its own pin. */
|
|
1303
|
+
protected chainPin(): string | undefined;
|
|
815
1304
|
/** One request, bounded by `timeoutMs` (headers and body): a node that never answers fails with `RequestTimeoutError` instead of hanging. */
|
|
816
1305
|
private call;
|
|
817
1306
|
status(): Promise<any>;
|
|
818
|
-
|
|
1307
|
+
/**
|
|
1308
|
+
* Block headers, newest first: `{ height, hash, timestamp_ms, proposer, state_root, tx_count, … }`.
|
|
1309
|
+
* Up to `limit` (at most 100) below height `before` (default: from the head), so a page's
|
|
1310
|
+
* last height is the next page's `before`. Nothing older than the node's `history_from`.
|
|
1311
|
+
* `blocks(20)` still works.
|
|
1312
|
+
*/
|
|
1313
|
+
blocks(page?: number | {
|
|
1314
|
+
limit?: number;
|
|
1315
|
+
before?: number;
|
|
1316
|
+
}): Promise<any[]>;
|
|
1317
|
+
/**
|
|
1318
|
+
* An account's history, newest first, a page at a time (TR-3): pass the previous page's `next`
|
|
1319
|
+
* as `before` until it's `null`. Each tx is shown as `/api/tx` shows it. On nodes without paged
|
|
1320
|
+
* history it's the newest 25 and the pending ones, with `paged: false` (see `HistoryPage`).
|
|
1321
|
+
*/
|
|
1322
|
+
history(account: string, page?: {
|
|
1323
|
+
before?: string;
|
|
1324
|
+
limit?: number;
|
|
1325
|
+
}): Promise<HistoryPage>;
|
|
819
1326
|
block(heightOrHash: number | string): Promise<any>;
|
|
820
1327
|
tx(id: string): Promise<any>;
|
|
821
1328
|
account(addressOrName: string): Promise<any>;
|
|
@@ -884,6 +1391,82 @@ export declare class Client {
|
|
|
884
1391
|
distribution(id: number): Promise<any>;
|
|
885
1392
|
/** A multisig account: owners, threshold, open proposals and their approvals. */
|
|
886
1393
|
multisig(account: string): Promise<any>;
|
|
1394
|
+
/**
|
|
1395
|
+
* The chain's fuel prices and program bounds now (`/api/fees`' `fuel` section), checked.
|
|
1396
|
+
* `ProgramsOffError` when programs have never been switched on there (the section is absent).
|
|
1397
|
+
*/
|
|
1398
|
+
programFuel(): Promise<ProgramFuel>;
|
|
1399
|
+
/** The programs parameters a deposit is priced with (`/api/params`' `programs` section), checked. */
|
|
1400
|
+
programParams(): Promise<ProgramParams>;
|
|
1401
|
+
/**
|
|
1402
|
+
* A program by its address (never a name): its record, the version digest a call binds (recomputed
|
|
1403
|
+
* from its code, interface and version: a node whose digest isn't what those compute is refused),
|
|
1404
|
+
* who could upgrade it, what it holds and its methods, whose names are the deployer's
|
|
1405
|
+
* (`untrusted_name`). One node's word (`proven: false`): `provenProgram` proves the record itself.
|
|
1406
|
+
*/
|
|
1407
|
+
program(address: string): Promise<ProgramInfo>;
|
|
1408
|
+
/**
|
|
1409
|
+
* A stored code by its hash: its size, who uploaded it and for what deposit, how many programs use
|
|
1410
|
+
* it, when it was stored (usable from the block after) and its exported methods (`untrusted_exports`).
|
|
1411
|
+
* With `wasm`, the code itself too, checked to hash to what was asked for.
|
|
1412
|
+
*/
|
|
1413
|
+
code(hash: string, opts?: {
|
|
1414
|
+
wasm?: boolean;
|
|
1415
|
+
}): Promise<ProgramCodeInfo>;
|
|
1416
|
+
/**
|
|
1417
|
+
* A stored interface by its hash: its format-1 bytes (checked to hash to what was asked for) and
|
|
1418
|
+
* the node's JSON reading of them (`untrusted_interface`, every name the deployer's, not checked
|
|
1419
|
+
* against the bytes: this SDK has no interface decoder yet).
|
|
1420
|
+
*/
|
|
1421
|
+
interface(hash: string): Promise<ProgramInterfaceInfo>;
|
|
1422
|
+
/**
|
|
1423
|
+
* Runs a program's `view` method on the node, as of its newest block: nothing is signed or paid.
|
|
1424
|
+
* `input` is what the method reads (bytes, or lowercase hex); `bindings` name the other programs
|
|
1425
|
+
* it may reach (a program's address, and the version digest it must be at, or none for "any
|
|
1426
|
+
* version", which a read may take); `fuel` caps the run (the node caps it too). The answer's
|
|
1427
|
+
* `return_data` is the program's own claim, which the chain checks nothing of. Refused views
|
|
1428
|
+
* (`ApiError`: 403 when the node serves none, 429 with `retryAfterMs`, 400/404/422 for a request
|
|
1429
|
+
* the node won't run) never ran.
|
|
1430
|
+
*/
|
|
1431
|
+
view(address: string, method: string, input?: Uint8Array | string, opts?: {
|
|
1432
|
+
bindings?: {
|
|
1433
|
+
program: string;
|
|
1434
|
+
versionDigest?: string;
|
|
1435
|
+
}[];
|
|
1436
|
+
fuel?: number;
|
|
1437
|
+
}): Promise<ProgramViewResult>;
|
|
1438
|
+
/**
|
|
1439
|
+
* A program's record, proven: its Merkle proof (namespace 66) checked against the state root the
|
|
1440
|
+
* node reports, which each of `witnesses` must report too, and fresh (see `provenRecord`).
|
|
1441
|
+
* The record is decoded here and its `version_digest` recomputed from its own fields, so a call
|
|
1442
|
+
* built from it binds the code the chain holds. `null` if the program provably doesn't exist.
|
|
1443
|
+
* Without witnesses it's only as sure as this node (it can't be called proven).
|
|
1444
|
+
*/
|
|
1445
|
+
provenProgram(address: string, opts?: ProvenOptions): Promise<{
|
|
1446
|
+
creator: string;
|
|
1447
|
+
created_at: number;
|
|
1448
|
+
wasm_hash: string;
|
|
1449
|
+
interface_hash: string;
|
|
1450
|
+
version: number;
|
|
1451
|
+
authority: string | null;
|
|
1452
|
+
upgrade_delay_blocks: number;
|
|
1453
|
+
policy: "open" | "additive";
|
|
1454
|
+
accepts_transfers: boolean;
|
|
1455
|
+
storage: {
|
|
1456
|
+
items: number;
|
|
1457
|
+
bytes: number;
|
|
1458
|
+
deposit: string;
|
|
1459
|
+
};
|
|
1460
|
+
sponsored: string;
|
|
1461
|
+
record_deposit: string;
|
|
1462
|
+
record_payer: string;
|
|
1463
|
+
address: string;
|
|
1464
|
+
version_digest: string;
|
|
1465
|
+
witnesses: number;
|
|
1466
|
+
height: number;
|
|
1467
|
+
root: string;
|
|
1468
|
+
head: number;
|
|
1469
|
+
} | null>;
|
|
887
1470
|
/** `/api/proof/{namespace}/{key}`, unchecked. Prefer `provenRecord`. */
|
|
888
1471
|
proof(namespace: number, key: string | Uint8Array): Promise<ProofResponse>;
|
|
889
1472
|
/**
|
|
@@ -967,6 +1550,14 @@ export declare class Client {
|
|
|
967
1550
|
* - `TxPendingError`: it was admitted and may still execute. Don't send it again blindly.
|
|
968
1551
|
*/
|
|
969
1552
|
submit(tx: Tx, wait?: boolean): Promise<any>;
|
|
1553
|
+
/**
|
|
1554
|
+
* Submits a signed tx and returns its id, without reading it back or waiting (`submit` does
|
|
1555
|
+
* both). The same bytes can be posted again safely: a node answers with the same id, and the tx
|
|
1556
|
+
* runs at most once. As JSON, or in its wire form with `wireTxs`. Errors as `submit`'s.
|
|
1557
|
+
*/
|
|
1558
|
+
post(tx: Tx): Promise<{
|
|
1559
|
+
id: string;
|
|
1560
|
+
}>;
|
|
970
1561
|
faucet(to: string, wait?: boolean): Promise<any>;
|
|
971
1562
|
/**
|
|
972
1563
|
* Polls a tx until it's finalized (returns it) or failed (`TxFailedError`, which says whether it
|