@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
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
/** The most code one upload carries, in bytes (`MAX_CODE_BYTES`). */
|
|
2
|
+
export declare const MAX_PROGRAM_CODE_BYTES: number;
|
|
3
|
+
/** The most interface one upload carries, in bytes (`MAX_INTERFACE_BYTES`). */
|
|
4
|
+
export declare const MAX_PROGRAM_INTERFACE_BYTES: number;
|
|
5
|
+
/** The most input one call carries, in bytes (`MAX_INPUT`). */
|
|
6
|
+
export declare const MAX_PROGRAM_INPUT_BYTES: number;
|
|
7
|
+
/** The most calls one `call_program` runs (`MAX_CALLS`). */
|
|
8
|
+
export declare const MAX_PROGRAM_CALLS = 8;
|
|
9
|
+
/** The most programs one transaction binds (`MAX_BINDINGS`). */
|
|
10
|
+
export declare const MAX_PROGRAM_BINDINGS = 16;
|
|
11
|
+
/** What a program's record adds to program state's bytes, so what its creator bonds a deposit for (`RECORD_BYTES`). */
|
|
12
|
+
export declare const PROGRAM_RECORD_BYTES = 256n;
|
|
13
|
+
/** The fuel rate is in milli-drops per fuel: a fee is `rate × reserved / 1000` (`econ::RATE_SCALE`). */
|
|
14
|
+
export declare const FUEL_RATE_SCALE = 1000n;
|
|
15
|
+
/**
|
|
16
|
+
* A binding's version digest of 64 zeros: "any version of that program". A transaction that binds
|
|
17
|
+
* it runs whatever code the program has when it runs, which is not what its signer was shown: this
|
|
18
|
+
* SDK signs it only when asked to, never by default.
|
|
19
|
+
*/
|
|
20
|
+
export declare const ANY_PROGRAM_VERSION: string;
|
|
21
|
+
/**
|
|
22
|
+
* The fuel schedule these numbers belong to (node/vm/src/meter.rs `SCHEDULE_V0`, `fuel.schedule`
|
|
23
|
+
* 0 in `/api/fees`). A node that prices fuel by another schedule, or reports other numbers for this
|
|
24
|
+
* one, is refused: the SDK prices what it signs with these.
|
|
25
|
+
*/
|
|
26
|
+
export declare const SCHEDULE_V0: Readonly<{
|
|
27
|
+
schedule: 0;
|
|
28
|
+
load_base: 10000n;
|
|
29
|
+
load_per_byte: 40n;
|
|
30
|
+
upload_base: 50000n;
|
|
31
|
+
upload_per_byte: 71n;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* A node answered a question about programs with something no honest node says (a digest that isn't
|
|
35
|
+
* 64 lowercase hex, an amount that isn't a decimal string, a height the chain can't have, …). Nothing
|
|
36
|
+
* from the answer was used and nothing was signed on its word: ask another node.
|
|
37
|
+
*/
|
|
38
|
+
export declare class ProgramAnswerError extends Error {
|
|
39
|
+
readonly rpc: string;
|
|
40
|
+
readonly what: string;
|
|
41
|
+
readonly field: string;
|
|
42
|
+
readonly problem: string;
|
|
43
|
+
constructor(rpc: string, what: string, field: string, problem: string);
|
|
44
|
+
}
|
|
45
|
+
/** The chain hasn't switched programs on (`/api/fees` has no `fuel` section): nothing was signed. */
|
|
46
|
+
export declare class ProgramsOffError extends Error {
|
|
47
|
+
readonly rpc: string;
|
|
48
|
+
constructor(rpc: string);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A transaction would reserve more fuel than one block counts (`program_max_block_fuel`), so no
|
|
52
|
+
* block could include it: refused before it's signed. `reserved` is its fuel to run plus the load
|
|
53
|
+
* of the code it declares.
|
|
54
|
+
*/
|
|
55
|
+
export declare class FuelReservationError extends Error {
|
|
56
|
+
readonly reserved: bigint;
|
|
57
|
+
readonly run: bigint;
|
|
58
|
+
readonly load: bigint;
|
|
59
|
+
readonly limit: bigint;
|
|
60
|
+
constructor(reserved: bigint, run: bigint, load: bigint, limit: bigint);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Text a node or a program chose, made inert before it's quoted anywhere (an error, a sentence):
|
|
64
|
+
* stripped of control, format (bidi, zero-width), private-use, surrogate and line and paragraph
|
|
65
|
+
* separator characters, as the MCP's `clean()` does. JSON quoting escapes control characters but
|
|
66
|
+
* not the format ones (U+202E would still reorder the line), so every quote goes through this first.
|
|
67
|
+
*/
|
|
68
|
+
export declare const plainText: (s: string) => string;
|
|
69
|
+
/** An account as the node labels it. */
|
|
70
|
+
export interface AccountLabel {
|
|
71
|
+
address: string;
|
|
72
|
+
/** A `.boo` name that account owns, or a system label: a stranger's text. */
|
|
73
|
+
name: string | null;
|
|
74
|
+
short: string;
|
|
75
|
+
}
|
|
76
|
+
/** A program's address as a caller gives it: never a name, which moves with its owner (docs/PROGRAMS-V0.md §8.1). */
|
|
77
|
+
export declare function programAddressArg(s: unknown, what?: string): string;
|
|
78
|
+
/** A code, interface or version digest as a caller gives it: 64 lowercase hex characters. */
|
|
79
|
+
export declare function programHashArg(s: unknown, what: string): string;
|
|
80
|
+
/** A method name: an identifier, as the chain's interfaces name them (`[a-z][a-z0-9_]{0,31}`). */
|
|
81
|
+
export declare function programMethodArg(s: unknown): string;
|
|
82
|
+
/** Bytes as a caller gives them (code, an interface, an input): raw, or lowercase hex of whole bytes; at most `max`. */
|
|
83
|
+
export declare function programBytesArg(v: unknown, what: string, max: number): Uint8Array;
|
|
84
|
+
/** A call's input as the request and the transaction carry it: lowercase hex, at most `MAX_PROGRAM_INPUT_BYTES`. */
|
|
85
|
+
export declare const programInputArg: (v: unknown) => string;
|
|
86
|
+
/** A fuel amount a caller gives: a whole number from 1 to 2^53 − 1 (the chain's own bound is lower). */
|
|
87
|
+
export declare function positiveFuel(n: unknown): number;
|
|
88
|
+
/** A type in an interface (node/src/programs/interface_json.rs `TypeJson`): scalars as strings, the rest as one-key objects. */
|
|
89
|
+
export type ProgramType = string | {
|
|
90
|
+
bytes: number;
|
|
91
|
+
} | {
|
|
92
|
+
text: number;
|
|
93
|
+
} | {
|
|
94
|
+
option: ProgramType;
|
|
95
|
+
} | {
|
|
96
|
+
vec: [ProgramType, number];
|
|
97
|
+
};
|
|
98
|
+
/** A method of a program's interface, as `/api/program` serves it. Its names are the deployer's. */
|
|
99
|
+
export interface ProgramMethod {
|
|
100
|
+
/** The deployer's identifier for it: an untrusted claim. */
|
|
101
|
+
untrusted_name: string;
|
|
102
|
+
/** The method's selector, 16 hex: BLAKE3 of its name (`methodSelector`). */
|
|
103
|
+
selector: string;
|
|
104
|
+
/** What the chain enforces: `call` (a transaction), `view` (a read) or `init` (once, when the program is created). */
|
|
105
|
+
kind: "call" | "view" | "init";
|
|
106
|
+
payable: boolean;
|
|
107
|
+
args: {
|
|
108
|
+
untrusted_name: string;
|
|
109
|
+
type: ProgramType;
|
|
110
|
+
}[];
|
|
111
|
+
returns: ProgramType | null;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A program as a node serves it (`GET /api/program/{address}`), checked: its `version_digest` is
|
|
115
|
+
* the one its own hashes and version compute (so a node can't show one program's code under
|
|
116
|
+
* another's digest), and its numbers and digests are well formed. `proven: false`: this is one
|
|
117
|
+
* node's word (`Client.provenProgram` proves the record itself against witnesses).
|
|
118
|
+
*/
|
|
119
|
+
export interface ProgramInfo {
|
|
120
|
+
address: string;
|
|
121
|
+
creator: AccountLabel;
|
|
122
|
+
created_at: number;
|
|
123
|
+
code: {
|
|
124
|
+
wasm_hash: string;
|
|
125
|
+
size: number | null;
|
|
126
|
+
interface_hash: string;
|
|
127
|
+
};
|
|
128
|
+
version: number;
|
|
129
|
+
/** What a call to this program binds (`versionDigest`), recomputed from `code` and `version`, never taken on trust. */
|
|
130
|
+
version_digest: string;
|
|
131
|
+
authority: AccountLabel | null;
|
|
132
|
+
upgrade_delay_blocks: number;
|
|
133
|
+
policy: "open" | "additive";
|
|
134
|
+
/** The node's sentence about who may upgrade it: its words, not a rule. */
|
|
135
|
+
upgradability: string;
|
|
136
|
+
accepts_transfers: boolean;
|
|
137
|
+
/** Drops it holds, as a decimal string. */
|
|
138
|
+
balance: string;
|
|
139
|
+
storage: {
|
|
140
|
+
items: number;
|
|
141
|
+
bytes: number;
|
|
142
|
+
deposit: string;
|
|
143
|
+
sponsored: string;
|
|
144
|
+
};
|
|
145
|
+
record_deposit: string;
|
|
146
|
+
record_payer: AccountLabel;
|
|
147
|
+
/** Its interface's methods; `null` only if the node's state is broken. The names are the deployer's. */
|
|
148
|
+
methods: ProgramMethod[] | null;
|
|
149
|
+
/** Where `/api/proof` serves this record. */
|
|
150
|
+
proof_path: string;
|
|
151
|
+
/** The block the node read it at. */
|
|
152
|
+
height: number;
|
|
153
|
+
proven: false;
|
|
154
|
+
}
|
|
155
|
+
/** `GET /api/program/{address}` checked against what was asked (`address`) and the chain's clock (`clock`: refuses a height the chain can't have reached). */
|
|
156
|
+
export declare function checkProgram(rpc: string, address: string, raw: unknown, clock?: (height: number) => void): ProgramInfo;
|
|
157
|
+
/** A stored code as `GET /api/code/{hash}` serves it, checked. */
|
|
158
|
+
export interface ProgramCodeInfo {
|
|
159
|
+
wasm_hash: string;
|
|
160
|
+
size: number;
|
|
161
|
+
/** The method names its exported functions carry (`bk_<name>`): the deployer's. */
|
|
162
|
+
untrusted_exports: string[];
|
|
163
|
+
uploader: AccountLabel | null;
|
|
164
|
+
/** What was bonded for it, drops. */
|
|
165
|
+
deposit: string | null;
|
|
166
|
+
/** How many programs use it. */
|
|
167
|
+
refs: number | null;
|
|
168
|
+
/** The block that stored it: usable from the block after. */
|
|
169
|
+
uploaded_at: number | null;
|
|
170
|
+
last_used_at: number | null;
|
|
171
|
+
/** The code itself, when it was asked for (`?wasm=1`) and its hash checked out. */
|
|
172
|
+
wasm?: Uint8Array;
|
|
173
|
+
height: number;
|
|
174
|
+
}
|
|
175
|
+
/** `GET /api/code/{hash}[?wasm=1]` checked: it's the code asked for, and when the bytes came they hash to it. */
|
|
176
|
+
export declare function checkCode(rpc: string, hash: string, raw: unknown, wantWasm: boolean, clock?: (height: number) => void): ProgramCodeInfo;
|
|
177
|
+
/** A stored interface as `GET /api/interface/{hash}` serves it, checked. */
|
|
178
|
+
export interface ProgramInterfaceInfo {
|
|
179
|
+
interface_hash: string;
|
|
180
|
+
size: number;
|
|
181
|
+
/** The interface's format-1 bytes (docs/PROGRAMS-V0.md §3.2), which hash to `interface_hash`. */
|
|
182
|
+
bytes: Uint8Array;
|
|
183
|
+
hex: string;
|
|
184
|
+
/**
|
|
185
|
+
* The node's reading of those bytes as JSON (§3.4): every name in it is the deployer's. It isn't
|
|
186
|
+
* checked against the bytes (this SDK has no interface decoder yet): the bytes are what `interface_hash` names.
|
|
187
|
+
*/
|
|
188
|
+
untrusted_interface: unknown;
|
|
189
|
+
uploader: AccountLabel | null;
|
|
190
|
+
deposit: string | null;
|
|
191
|
+
refs: number | null;
|
|
192
|
+
uploaded_at: number | null;
|
|
193
|
+
last_used_at: number | null;
|
|
194
|
+
height: number;
|
|
195
|
+
}
|
|
196
|
+
/** `GET /api/interface/{hash}` checked: it's the interface asked for, and its bytes hash to it. */
|
|
197
|
+
export declare function checkInterface(rpc: string, hash: string, raw: unknown, clock?: (height: number) => void): ProgramInterfaceInfo;
|
|
198
|
+
/** How a failed program run ended (docs/PROGRAMS-V0.md §8.1's table): numbers, never engine text. */
|
|
199
|
+
export interface ProgramOutcome {
|
|
200
|
+
ok: boolean;
|
|
201
|
+
/** The outcome's number in §8.1's table (0 for ok). */
|
|
202
|
+
number: number;
|
|
203
|
+
/** `ok`, or the table's code: `trapped`, `aborted`, `commit`, `value_cap`, `exit_only`, `storage_limit`, `state_full`, `invalid_code`, `translation_refused`, `interface_mismatch`, `native`. */
|
|
204
|
+
code: string;
|
|
205
|
+
/** Where a trap or an abort began. */
|
|
206
|
+
program?: string;
|
|
207
|
+
trap?: {
|
|
208
|
+
number: number;
|
|
209
|
+
name: string;
|
|
210
|
+
};
|
|
211
|
+
abort_code?: number;
|
|
212
|
+
/** An abort's own message (at most 256 bytes, sanitized by the VM): the program's words. */
|
|
213
|
+
untrusted_message?: string;
|
|
214
|
+
commit_error?: number;
|
|
215
|
+
/** A value cap failure's cap and the control it would have left, drops. */
|
|
216
|
+
cap?: string;
|
|
217
|
+
control?: string;
|
|
218
|
+
rule?: {
|
|
219
|
+
number: number;
|
|
220
|
+
name: string;
|
|
221
|
+
};
|
|
222
|
+
func?: number;
|
|
223
|
+
offset?: number;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* A failed outcome in words, from its numbers and the chain's own names for them (docs/PROGRAMS-V0.md
|
|
227
|
+
* §8.1): never engine text, and **never what the program wrote**: an abort's own message stays in
|
|
228
|
+
* `outcome.untrusted_message`, for the caller to show as data. These words end up in exceptions that
|
|
229
|
+
* agent frameworks hand to models, and a stranger's text doesn't belong in them. Tolerant of an
|
|
230
|
+
* outcome that wasn't checked (a field of another type reads as `?`): it never throws on a node's
|
|
231
|
+
* odd answer. `storageLimit` is the limit the failed transaction signed, drops: a call that traps
|
|
232
|
+
* `storage_limit` was refused its writes' deposit by it (the default for a call is 0, which consents
|
|
233
|
+
* to no new storage), and says so.
|
|
234
|
+
*/
|
|
235
|
+
export declare function outcomeWords(o: ProgramOutcome, storageLimit?: bigint): string;
|
|
236
|
+
/** What a `View` method returned (`POST /api/program/{address}/view`), checked. */
|
|
237
|
+
export interface ProgramViewResult {
|
|
238
|
+
ok: boolean;
|
|
239
|
+
outcome: ProgramOutcome;
|
|
240
|
+
/**
|
|
241
|
+
* What the method returned, lowercase hex: `""` when it returns nothing, `null` when it failed.
|
|
242
|
+
* It's the program's own claim: the chain checks none of it.
|
|
243
|
+
*/
|
|
244
|
+
return_data: string | null;
|
|
245
|
+
fuel_used: number;
|
|
246
|
+
/** The newest block this node executed: the view read the state after it, and ran as of the block after. */
|
|
247
|
+
height: number;
|
|
248
|
+
}
|
|
249
|
+
export declare function checkView(rpc: string, address: string, raw: unknown, clock?: (height: number) => void): ProgramViewResult;
|
|
250
|
+
/** The chain's fuel prices and program bounds now (`/api/fees`' `fuel` section), checked. Rates are milli-drops per fuel. */
|
|
251
|
+
export interface ProgramFuel {
|
|
252
|
+
/** `on`; `exit_only` (switched off by governance: only calls that send no FANG); `paused` (nothing but a pause). */
|
|
253
|
+
status: "on" | "exit_only" | "paused";
|
|
254
|
+
/** What the next block charges. */
|
|
255
|
+
rate: bigint;
|
|
256
|
+
floor_rate: bigint;
|
|
257
|
+
/** The most the rate can reach in the next 17 blocks of full fuel: a fee priced with it covers any of them. */
|
|
258
|
+
suggested_rate: bigint;
|
|
259
|
+
max_tx_fuel: bigint;
|
|
260
|
+
max_block_fuel: bigint;
|
|
261
|
+
max_tx_code_bytes: number;
|
|
262
|
+
/** Program state's accounted bytes, and the soft cap its price curve doubles around. */
|
|
263
|
+
state_bytes: bigint;
|
|
264
|
+
state_soft_bytes: bigint;
|
|
265
|
+
/** What a byte of storage costs now, drops; `null` past the ceiling. */
|
|
266
|
+
storage_price: bigint | null;
|
|
267
|
+
paused_until: number | null;
|
|
268
|
+
}
|
|
269
|
+
/** `/api/fees`' `fuel` section: the chain's, or `ProgramsOffError` when it has none (programs never switched on). */
|
|
270
|
+
export declare function checkFuel(rpc: string, raw: unknown): ProgramFuel;
|
|
271
|
+
/** The programs parameters a client prices with (`/api/params`' `programs.params`), checked. */
|
|
272
|
+
export interface ProgramParams {
|
|
273
|
+
/** Drops per accounted byte at an empty state (`program_storage_price`): the price curve doubles it. */
|
|
274
|
+
storage_price: bigint;
|
|
275
|
+
/** `program_min_upgrade_delay_blocks`: the notice an upgrade authority must give. */
|
|
276
|
+
min_upgrade_delay_blocks: number;
|
|
277
|
+
}
|
|
278
|
+
export declare function checkParams(rpc: string, raw: unknown): ProgramParams;
|
|
279
|
+
/** The fuel to load one distinct code of `size` bytes (schedule 0: `load_base + load_per_byte × size`, §5.1). */
|
|
280
|
+
export declare const loadFuel: (size: number | bigint) => bigint;
|
|
281
|
+
/** The fuel an upload of `code` bytes of WebAssembly and `iface` bytes of interface reserves (§5.1's `upload_fuel`: its whole `exec`). */
|
|
282
|
+
export declare const uploadFuel: (code: number | bigint, iface: number | bigint) => bigint;
|
|
283
|
+
/** The fuel fee of `reserved` fuel at `rate` milli-drops per fuel: `rate × reserved / 1000`, rounded down (§5.1). Burned, never refunded. */
|
|
284
|
+
export declare const fuelFee: (rate: bigint, reserved: bigint) => bigint;
|
|
285
|
+
/** What a transaction reserves: its fuel to run, the load of the distinct code it declares, and the two together. */
|
|
286
|
+
export interface FuelReservation {
|
|
287
|
+
run: bigint;
|
|
288
|
+
load: bigint;
|
|
289
|
+
reserved: bigint;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Whether a block could carry `run` fuel and the load of the `declared` code (each distinct code
|
|
293
|
+
* hash once, with its size): refused as admission refuses it, before anything is signed. A
|
|
294
|
+
* reservation past `max_block_fuel` is a `FuelReservationError`; code past what one transaction may
|
|
295
|
+
* load, or a fuel limit past `max_tx_fuel` (`execFuelLimited`: a create's or a call's own limit, not
|
|
296
|
+
* an upload's), is an `Error` that says so.
|
|
297
|
+
*/
|
|
298
|
+
export declare function reserveFuel(fuel: ProgramFuel, run: bigint, declared: Map<string, number>, execFuelLimited?: boolean): FuelReservation;
|
|
299
|
+
/**
|
|
300
|
+
* The fuel limit a call or an initializer is signed with when the caller gives none (docs/PROGRAMS-V0.md
|
|
301
|
+
* §8.4): `min(program_max_tx_fuel, program_max_block_fuel − load)`, the most one transaction may run
|
|
302
|
+
* that a block can still carry beside the load of the `declared` code. With the parameters at their
|
|
303
|
+
* defaults that's `program_max_tx_fuel`; with `program_max_tx_fuel` = `program_max_block_fuel` (both
|
|
304
|
+
* legal) a bare `program_max_tx_fuel` would itself trip the refusal of a reservation past the block.
|
|
305
|
+
* When the load alone fills the block there is no room: 1, which `reserveFuel` then refuses in words.
|
|
306
|
+
*/
|
|
307
|
+
export declare function defaultFuelLimit(fuel: ProgramFuel, declared: Map<string, number>): bigint;
|
|
308
|
+
/**
|
|
309
|
+
* The fuel fee of a reservation (drops) at the rate the next 17 blocks can reach (`suggested_rate`:
|
|
310
|
+
* what a transaction's `fee` is priced at, §5.5) and at the floor rate (what the tip cap is counted
|
|
311
|
+
* on: a block's rate is never below it), after holding it to `max_block_fuel` once more against
|
|
312
|
+
* these very prices. Burned, and never refunded: a transaction pays for what it reserves.
|
|
313
|
+
*/
|
|
314
|
+
export declare function priceFuel(fuel: ProgramFuel, r: FuelReservation): {
|
|
315
|
+
suggested: bigint;
|
|
316
|
+
floor: bigint;
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* Whether the chain's programs status admits this kind of transaction now: `on` admits all;
|
|
320
|
+
* `exit_only` only a call that sends no FANG (an exit); `paused` none. The node refuses the rest at
|
|
321
|
+
* submission, so this only says so before a signature (`sendsValue`: the transaction attaches FANG).
|
|
322
|
+
*/
|
|
323
|
+
export declare function checkProgramsStatus(fuel: ProgramFuel, kind: "upload" | "create" | "call", sendsValue: boolean): void;
|
|
324
|
+
/**
|
|
325
|
+
* The price of a byte of program state when it holds `used` bytes (node/vm/src/storage.rs `price`):
|
|
326
|
+
* `base × 2^⌊8 × used / soft⌋`. `null` past the ceiling (`2 × soft`) or if the price wouldn't fit a u64.
|
|
327
|
+
*/
|
|
328
|
+
export declare function programStoragePrice(base: bigint, soft: bigint, used: bigint): bigint | null;
|
|
329
|
+
/**
|
|
330
|
+
* What an upload bonds (node/src/program_cli.rs `Bounds::upload_deposit`, §2.2 step 5): each blob that
|
|
331
|
+
* isn't stored yet, code first, at the price once it lands. `null` past program state's ceiling.
|
|
332
|
+
*/
|
|
333
|
+
export declare function programUploadDeposit(fuel: ProgramFuel, params: ProgramParams, blobs: {
|
|
334
|
+
size: number;
|
|
335
|
+
isNew: boolean;
|
|
336
|
+
}[]): bigint | null;
|
|
337
|
+
/** What a create bonds for its record (§2.3 step 2): `PROGRAM_RECORD_BYTES` at the price once it lands. `null` past the ceiling. */
|
|
338
|
+
export declare function programRecordDeposit(fuel: ProgramFuel, params: ProgramParams): bigint | null;
|
|
339
|
+
/** A deposit and ten percent more: the default `storage_limit` of an upload or a create (§8.3), room for the price to move. */
|
|
340
|
+
export declare const depositWithMargin: (deposit: bigint) => bigint;
|
|
341
|
+
/** What a program transaction's fee was made of, drops (§8.1): their sum is what it was charged. */
|
|
342
|
+
export interface ReceiptFee {
|
|
343
|
+
bytes: bigint;
|
|
344
|
+
fuel: bigint;
|
|
345
|
+
tip: bigint;
|
|
346
|
+
}
|
|
347
|
+
/** What a signer was debited outside the VM's own balance changes (§8.1), drops: `total` is the three parts' sum. */
|
|
348
|
+
export interface OutsideVm {
|
|
349
|
+
record_deposit: bigint;
|
|
350
|
+
upload_deposit: bigint;
|
|
351
|
+
account_creation_fee: bigint;
|
|
352
|
+
total: bigint;
|
|
353
|
+
}
|
|
354
|
+
/** The facts of a program transaction: what the chain did, which the state holds too. */
|
|
355
|
+
export interface ProgramFacts {
|
|
356
|
+
/** The VM's diff, net per account, drops (negative: a debit): a program's own sends and the signer's write bonds. Not the fee, not `outside_vm`. */
|
|
357
|
+
balance_changes: {
|
|
358
|
+
account: string;
|
|
359
|
+
change: bigint;
|
|
360
|
+
}[];
|
|
361
|
+
storage: {
|
|
362
|
+
bytes_delta: number;
|
|
363
|
+
bonded: bigint;
|
|
364
|
+
refunded: bigint;
|
|
365
|
+
};
|
|
366
|
+
outside_vm: OutsideVm;
|
|
367
|
+
/** Drops the VM's diff burned: the creation fees of the accounts a program's own sends opened. Taken from the programs' balances inside the diff, never the signer's. */
|
|
368
|
+
burned_by_programs: bigint;
|
|
369
|
+
fuel: {
|
|
370
|
+
limit: bigint;
|
|
371
|
+
load: bigint;
|
|
372
|
+
used: bigint;
|
|
373
|
+
reserved: bigint;
|
|
374
|
+
rate: bigint;
|
|
375
|
+
};
|
|
376
|
+
fee: ReceiptFee;
|
|
377
|
+
/** The program a create made. */
|
|
378
|
+
created: string | null;
|
|
379
|
+
upload: {
|
|
380
|
+
wasm_hash: string;
|
|
381
|
+
interface_hash: string;
|
|
382
|
+
new_code: boolean;
|
|
383
|
+
new_interface: boolean;
|
|
384
|
+
deposit: bigint;
|
|
385
|
+
} | null;
|
|
386
|
+
}
|
|
387
|
+
/** What the programs said happened: claims, which the chain checks nothing of. Method and event names are the deployer's. */
|
|
388
|
+
export interface ProgramClaims {
|
|
389
|
+
return_data: {
|
|
390
|
+
program: string;
|
|
391
|
+
untrusted_method: string;
|
|
392
|
+
value: bigint;
|
|
393
|
+
data: string;
|
|
394
|
+
}[];
|
|
395
|
+
events: {
|
|
396
|
+
program: string;
|
|
397
|
+
untrusted_name: string;
|
|
398
|
+
data: string;
|
|
399
|
+
}[];
|
|
400
|
+
/** Set when the block's claims budget left this receipt's claims out (its facts are all kept). */
|
|
401
|
+
omitted: {
|
|
402
|
+
events: number;
|
|
403
|
+
event_bytes: number;
|
|
404
|
+
return_bytes: number;
|
|
405
|
+
} | null;
|
|
406
|
+
}
|
|
407
|
+
/** A program transaction's receipt as `/api/tx/{id}` serves it, checked: facts apart from claims. */
|
|
408
|
+
export interface ProgramReceipt {
|
|
409
|
+
version: number;
|
|
410
|
+
kind: "upload" | "create" | "call";
|
|
411
|
+
outcome: ProgramOutcome;
|
|
412
|
+
facts: ProgramFacts;
|
|
413
|
+
claims: ProgramClaims;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* The `program` section of a `/api/tx` answer, checked: `null` for a program transaction with no
|
|
417
|
+
* receipt to show (still pending, or its block pruned from this node). Every amount is a decimal
|
|
418
|
+
* string, every digest 64 lowercase hex, and the sums the node states are recomputed: the fee parts
|
|
419
|
+
* equal the transaction's `fee`, `outside_vm.total` is its parts' sum, `reserved` is `limit + load`.
|
|
420
|
+
* A transaction that isn't a program's carries no `program` key, and `ProgramAnswerError` says so.
|
|
421
|
+
*/
|
|
422
|
+
export declare function checkReceipt(rpc: string, tx: unknown): ProgramReceipt | null;
|
|
423
|
+
/** What a program transaction's fee came to, drops: bytes, fuel and tip (§8.1's `Σ`). */
|
|
424
|
+
export declare const chargedFee: (r: ProgramReceipt) => bigint;
|
|
425
|
+
/** What the VM's diff did to `account`'s balance, drops (0 for an account it doesn't list). */
|
|
426
|
+
export declare const vmChange: (r: ProgramReceipt, account: string) => bigint;
|
|
427
|
+
/**
|
|
428
|
+
* How far a receipt's facts are from conserving FANG (docs/PROGRAMS-V0.md §8.1): Σ `balance_changes` +
|
|
429
|
+
* (`storage.bonded` − `outside_vm.record_deposit` − `outside_vm.upload_deposit` − `storage.refunded`) +
|
|
430
|
+
* `burned_by_programs`. The VM's diff conserves (what its programs moved and the deposits it bonded
|
|
431
|
+
* or freed, plus what it burned, sum to nothing), and a create's record deposit and an upload's are
|
|
432
|
+
* bonded outside it: so a receipt the chain wrote is 0 here, and `checkReceipt` refuses one that
|
|
433
|
+
* isn't. (The account creation fee a create burns from its signer is the signer's, not a program's:
|
|
434
|
+
* it's in `outside_vm`, not here.)
|
|
435
|
+
*/
|
|
436
|
+
export declare const conservationGap: (f: Pick<ProgramFacts, "balance_changes" | "storage" | "outside_vm" | "burned_by_programs">) => bigint;
|
|
437
|
+
/**
|
|
438
|
+
* How the signer's balance moved, exactly (docs/PROGRAMS-V0.md §8.1, S6B-R1): Δbalance(signer) =
|
|
439
|
+
* −(fee total + `outside_vm.total`) + `balance_changes[signer]`. The fee is burned (and the tip goes
|
|
440
|
+
* to the proposer), the deposits and the account creation fee leave outside the VM, and the VM's diff
|
|
441
|
+
* holds what the programs moved, the signer's own write bonds among it. A failed transaction's receipt
|
|
442
|
+
* has no balance changes and nothing outside the VM: only the fee.
|
|
443
|
+
*/
|
|
444
|
+
export declare const signerChange: (r: ProgramReceipt, signer: string) => bigint;
|
|
445
|
+
/** `reconcileSigner`'s answer: what the receipt says the signer's balance did, what it did, and whether they're the same. */
|
|
446
|
+
export interface Reconciliation {
|
|
447
|
+
expected: bigint;
|
|
448
|
+
actual: bigint;
|
|
449
|
+
/** `actual − expected`: 0 when the balance moved exactly as the receipt says (nothing else touched the account between the two reads). */
|
|
450
|
+
difference: bigint;
|
|
451
|
+
exact: boolean;
|
|
452
|
+
/** Whether the receipt's own facts conserve FANG (`conservationGap` is 0): a receipt that doesn't can't be what the chain wrote. */
|
|
453
|
+
conserved: boolean;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* The signer's balance before and after its program transaction (both in drops, read around it with
|
|
457
|
+
* nothing else touching the account), held to `signerChange`.
|
|
458
|
+
*/
|
|
459
|
+
export declare function reconcileSigner(r: ProgramReceipt, signer: string, before: bigint, after: bigint): Reconciliation;
|
|
460
|
+
/** What a program transaction cost its signer, drops, from its receipt: the fee, what left outside the VM, what the VM took (the write bonds), and all of it. */
|
|
461
|
+
export interface ProgramCost {
|
|
462
|
+
/** Bytes, fuel and tip. */
|
|
463
|
+
fee: bigint;
|
|
464
|
+
/** Deposits and the account creation fee that left outside the VM's diff. */
|
|
465
|
+
outside_vm: OutsideVm;
|
|
466
|
+
/** What the VM's diff took from the signer (positive: a debit): its write bonds, and FANG it sent. 0 or less when the programs paid it. */
|
|
467
|
+
vm: bigint;
|
|
468
|
+
/** `fee + outside_vm.total + vm`: the signer's whole debit. */
|
|
469
|
+
total: bigint;
|
|
470
|
+
}
|
|
471
|
+
export declare function programCost(r: ProgramReceipt, signer: string): ProgramCost;
|