@geeqdev/geeq-sdk 0.0.1 → 0.1.1
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/.idea/geeq_sdk.iml +12 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.nvmrc +1 -0
- package/CONTRIBUTING.md +20 -0
- package/example/.env.example +4 -0
- package/example/README.md +304 -0
- package/example/USAGE.md +74 -0
- package/example/index.html +12 -0
- package/example/package-lock.json +1557 -0
- package/example/package.json +25 -0
- package/example/scripts/browser-check.mjs +1421 -0
- package/example/scripts/match-derivation.mjs +65 -0
- package/example/src/App.vue +138 -0
- package/example/src/components/AuthorityPanel.vue +277 -0
- package/example/src/components/ChainPanel.vue +267 -0
- package/example/src/components/ChainState.vue +59 -0
- package/example/src/components/CopyButton.vue +25 -0
- package/example/src/components/CreateAssetPanel.vue +313 -0
- package/example/src/components/DigitalAssetsPanel.vue +68 -0
- package/example/src/components/EvidencePanel.vue +396 -0
- package/example/src/components/ExplorerPanel.vue +119 -0
- package/example/src/components/KeypairPanel.vue +182 -0
- package/example/src/components/PhrasePanel.vue +105 -0
- package/example/src/components/SocketWarning.vue +18 -0
- package/example/src/components/StepGate.vue +24 -0
- package/example/src/components/TransferPanel.vue +416 -0
- package/example/src/components/TxDeadline.vue +19 -0
- package/example/src/components/TxFee.vue +31 -0
- package/example/src/components/TxStatus.vue +105 -0
- package/example/src/composables/useSocketConnection.ts +80 -0
- package/example/src/env.d.ts +12 -0
- package/example/src/main.ts +5 -0
- package/example/src/pennies.ts +7 -0
- package/example/src/style.css +149 -0
- package/example/tsconfig.json +19 -0
- package/example/vite.config.ts +26 -0
- package/jest.config.js +18 -0
- package/package.json +1 -5
- package/scripts/copy-wasm.mjs +21 -0
- package/scripts/smoke.mjs +382 -0
- package/src/address/record-type.ts +77 -0
- package/src/address/wallet-address.ts +105 -0
- package/src/amount.ts +143 -0
- package/src/assert.ts +30 -0
- package/src/capnp/README.md +15 -0
- package/src/capnp/adminNetTx.capnp.ts +66 -0
- package/src/capnp/appLayBlock.capnp.ts +26 -0
- package/src/capnp/appLayLedger.capnp.ts +35 -0
- package/src/capnp/appLayRec.capnp.ts +159 -0
- package/src/capnp/chainStateView.capnp.ts +49 -0
- package/src/capnp/coinAcctRec.capnp.ts +193 -0
- package/src/capnp/genesisBlock.capnp.ts +56 -0
- package/src/capnp/hubContentStmt.capnp.ts +59 -0
- package/src/capnp/misc.capnp.ts +19 -0
- package/src/capnp/netActorRec.capnp.ts +64 -0
- package/src/capnp/nodeContentStmt.capnp.ts +62 -0
- package/src/capnp/nodePayloadList.capnp.ts +28 -0
- package/src/capnp/nodeTxList.capnp.ts +37 -0
- package/src/capnp/paramAcctRec.capnp.ts +669 -0
- package/src/capnp/payload.capnp.ts +261 -0
- package/src/capnp/proxyAcctRec.capnp.ts +259 -0
- package/src/capnp/relayContentStmt.capnp.ts +85 -0
- package/src/capnp/sysAcctRec.capnp.ts +47 -0
- package/src/capnp/userAppTx.capnp.ts +269 -0
- package/src/capnp/userValTx.capnp.ts +1999 -0
- package/src/capnp/valLayBlock.capnp.ts +93 -0
- package/src/capnp/valLayLedger.capnp.ts +80 -0
- package/src/chain/geeq-chain.ts +1094 -0
- package/src/chain/geeq-node.ts +105 -0
- package/src/chain/nonce-guard.ts +73 -0
- package/src/chain/select.ts +149 -0
- package/src/crypto/account-id.ts +83 -0
- package/src/crypto/keypair.ts +221 -0
- package/src/crypto/mnemonic.ts +69 -0
- package/src/encoding/base64.ts +58 -0
- package/src/encoding/hex.ts +42 -0
- package/src/errors.ts +122 -0
- package/src/index.ts +195 -0
- package/src/ledger/coin-accounts.ts +73 -0
- package/src/ledger/decode.ts +147 -0
- package/src/ledger/geeq-ledger.ts +184 -0
- package/src/ledger/net-actors.ts +129 -0
- package/src/ledger/nft-records.ts +49 -0
- package/src/ledger/params.ts +82 -0
- package/src/ledger/proxy-accounts.ts +51 -0
- package/src/net/discovery.ts +231 -0
- package/src/net/explorer.ts +123 -0
- package/src/net/read-ledger.ts +58 -0
- package/src/net/routes.ts +79 -0
- package/src/net/transport.ts +221 -0
- package/src/net/websocket.ts +94 -0
- package/src/runtime/bindings.ts +38 -0
- package/src/runtime/init.ts +49 -0
- package/src/runtime/wasm-loader.browser.ts +22 -0
- package/src/runtime/wasm-loader.node.ts +16 -0
- package/src/socket/geeq-socket.ts +827 -0
- package/src/socket/tracked-tx.ts +319 -0
- package/src/socket/tx-status.ts +131 -0
- package/src/tx/attestation.ts +222 -0
- package/src/tx/content.ts +82 -0
- package/src/tx/encode.ts +107 -0
- package/src/tx/expiry.ts +11 -0
- package/src/tx/fee.ts +31 -0
- package/src/tx/metadata.ts +100 -0
- package/src/tx/nft.ts +108 -0
- package/src/tx/proxy.ts +156 -0
- package/src/tx/transfer.ts +162 -0
- package/src/types.ts +503 -0
- package/src/wasm/README.md +22 -0
- package/src/wasm/browser/geeq_core.d.ts +1224 -0
- package/src/wasm/browser/geeq_core.js +6014 -0
- package/src/wasm/browser/geeq_core_bg.wasm +0 -0
- package/src/wasm/browser/geeq_core_bg.wasm.d.ts +447 -0
- package/src/wasm/nodejs/geeq_core.d.ts +753 -0
- package/src/wasm/nodejs/geeq_core.js +6016 -0
- package/src/wasm/nodejs/geeq_core_bg.wasm +0 -0
- package/src/wasm/nodejs/geeq_core_bg.wasm.d.ts +447 -0
- package/src/wasm/nodejs/package.json +3 -0
- package/tsconfig.build.json +8 -0
- package/tsconfig.json +20 -0
- package/tsup.config.ts +60 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { invalidArgument } from '../errors'
|
|
2
|
+
import { WasmCoinType, WasmRecordType } from '../runtime/bindings'
|
|
3
|
+
import type { GeeqCoinType, GeeqRecordType } from '../types'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Applications speak in readable record-type names; the protocol speaks in
|
|
7
|
+
* numbers. This is the only place the two vocabularies meet.
|
|
8
|
+
*/
|
|
9
|
+
const RECORD_TYPE_TO_WASM: Readonly<Record<GeeqRecordType, number>> = {
|
|
10
|
+
'app-counterparty': WasmRecordType.AppCounterparty,
|
|
11
|
+
'app-dce': WasmRecordType.AppDce,
|
|
12
|
+
'app-nft': WasmRecordType.AppNft,
|
|
13
|
+
'app-stackable': WasmRecordType.AppStackable,
|
|
14
|
+
'coin-asset': WasmRecordType.CoinAsset,
|
|
15
|
+
'coin-hl': WasmRecordType.CoinHl,
|
|
16
|
+
'coin-micro': WasmRecordType.CoinMicro,
|
|
17
|
+
'gt-nwa': WasmRecordType.GtNwa,
|
|
18
|
+
'param-boolean': WasmRecordType.ParamBoolean,
|
|
19
|
+
'param-count-2': WasmRecordType.ParamCount2,
|
|
20
|
+
'param-count-8': WasmRecordType.ParamCount8,
|
|
21
|
+
'proxy-nft-mint': WasmRecordType.ProxyNftMint,
|
|
22
|
+
'proxy-funding': WasmRecordType.ProxyFunding,
|
|
23
|
+
'proxy-multisig': WasmRecordType.ProxyMultisig,
|
|
24
|
+
'proxy-dce': WasmRecordType.ProxyDce,
|
|
25
|
+
'proxy-token-mint': WasmRecordType.ProxyTokenMint,
|
|
26
|
+
sys: WasmRecordType.Sys,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const WASM_TO_RECORD_TYPE: ReadonlyMap<number, GeeqRecordType> = new Map(
|
|
30
|
+
(Object.entries(RECORD_TYPE_TO_WASM) as Array<[GeeqRecordType, number]>).map(
|
|
31
|
+
([name, value]) => [value, name],
|
|
32
|
+
),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
/** Every record type this SDK understands, for validation and tooling. */
|
|
36
|
+
export const GEEQ_RECORD_TYPES = Object.freeze(
|
|
37
|
+
Object.keys(RECORD_TYPE_TO_WASM) as GeeqRecordType[],
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
export const DEFAULT_RECORD_TYPE: GeeqRecordType = 'coin-asset'
|
|
41
|
+
|
|
42
|
+
/** @internal */
|
|
43
|
+
export function toWasmRecordType(recordType: GeeqRecordType): number {
|
|
44
|
+
const value = RECORD_TYPE_TO_WASM[recordType]
|
|
45
|
+
if (value === undefined) {
|
|
46
|
+
throw invalidArgument(
|
|
47
|
+
`Unknown record type "${String(recordType)}". Expected one of: ${GEEQ_RECORD_TYPES.join(', ')}.`,
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
return value
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** @internal */
|
|
54
|
+
export function fromWasmRecordType(value: number): GeeqRecordType {
|
|
55
|
+
const name = WASM_TO_RECORD_TYPE.get(value)
|
|
56
|
+
if (name === undefined) {
|
|
57
|
+
throw invalidArgument(
|
|
58
|
+
`The engine returned record type ${value}, which this SDK version does not know. ` +
|
|
59
|
+
'Your SDK is probably older than the chain you are talking to.',
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
return name
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const COIN_TYPE_TO_WASM: Readonly<Record<GeeqCoinType, number>> = {
|
|
66
|
+
mainnet: WasmCoinType.Mainnet,
|
|
67
|
+
testnet: WasmCoinType.Testnet,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** @internal */
|
|
71
|
+
export function toWasmCoinType(coinType: GeeqCoinType): number {
|
|
72
|
+
const value = COIN_TYPE_TO_WASM[coinType]
|
|
73
|
+
if (value === undefined) {
|
|
74
|
+
throw invalidArgument(`Unknown coin type "${String(coinType)}". Expected 'mainnet' or 'testnet'.`)
|
|
75
|
+
}
|
|
76
|
+
return value
|
|
77
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { GeeqError, invalidAddress, invalidArgument } from '../errors'
|
|
2
|
+
import { WasmWalletAddress } from '../runtime/bindings'
|
|
3
|
+
import { assertReady, initGeeq } from '../runtime/init'
|
|
4
|
+
import { resolveAccountId } from '../crypto/account-id'
|
|
5
|
+
import type { DecodedWalletAddress, GeeqRecordType, WalletAddressOptions } from '../types'
|
|
6
|
+
import { DEFAULT_RECORD_TYPE, fromWasmRecordType, toWasmRecordType } from './record-type'
|
|
7
|
+
|
|
8
|
+
/** Identify the account either by its public key or by its account id. */
|
|
9
|
+
export type AccountIdentifier =
|
|
10
|
+
| { readonly publicKey: Uint8Array; readonly accountId?: never }
|
|
11
|
+
| { readonly accountId: Uint8Array; readonly publicKey?: never }
|
|
12
|
+
|
|
13
|
+
export type CreateWalletAddressInput = AccountIdentifier & WalletAddressOptions
|
|
14
|
+
|
|
15
|
+
function assertChainNumber(chainNumber: number): void {
|
|
16
|
+
if (!Number.isInteger(chainNumber) || chainNumber < 0 || chainNumber > 0xffffffff) {
|
|
17
|
+
throw invalidArgument(
|
|
18
|
+
`chainNumber must be an integer between 0 and 4294967295, received ${String(chainNumber)}.`,
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Build the base58 wallet address for an account. Synchronous; requires the engine
|
|
25
|
+
* to be loaded already. Most callers want {@link createWalletAddress} instead.
|
|
26
|
+
*/
|
|
27
|
+
export function createWalletAddressSync(input: CreateWalletAddressInput): string {
|
|
28
|
+
assertReady('createWalletAddressSync')
|
|
29
|
+
assertChainNumber(input.chainNumber)
|
|
30
|
+
|
|
31
|
+
const recordType: GeeqRecordType = input.recordType ?? DEFAULT_RECORD_TYPE
|
|
32
|
+
const accountId = resolveAccountId(input)
|
|
33
|
+
|
|
34
|
+
let address: WasmWalletAddress | undefined
|
|
35
|
+
try {
|
|
36
|
+
address = WasmWalletAddress.new(input.chainNumber, toWasmRecordType(recordType), accountId)
|
|
37
|
+
return address.encode()
|
|
38
|
+
} catch (cause) {
|
|
39
|
+
throw invalidAddress(
|
|
40
|
+
`Could not build a wallet address for record type "${recordType}" on chain ${input.chainNumber}.`,
|
|
41
|
+
cause,
|
|
42
|
+
)
|
|
43
|
+
} finally {
|
|
44
|
+
address?.free()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Build the base58 wallet address for an account, loading the engine if needed.
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* const address = await createWalletAddress({ publicKey, chainNumber: 1 })
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export async function createWalletAddress(input: CreateWalletAddressInput): Promise<string> {
|
|
56
|
+
await initGeeq()
|
|
57
|
+
return createWalletAddressSync(input)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Decode a base58 wallet address. Synchronous; requires the engine to be loaded. */
|
|
61
|
+
export function decodeWalletAddressSync(address: string): DecodedWalletAddress {
|
|
62
|
+
assertReady('decodeWalletAddressSync')
|
|
63
|
+
|
|
64
|
+
if (typeof address !== 'string' || address.length === 0) {
|
|
65
|
+
throw invalidAddress('A wallet address must be a non-empty base58 string.')
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let decoded: WasmWalletAddress | undefined
|
|
69
|
+
try {
|
|
70
|
+
decoded = WasmWalletAddress.decode(address)
|
|
71
|
+
return Object.freeze({
|
|
72
|
+
address,
|
|
73
|
+
chainNumber: decoded.exportChainNum(),
|
|
74
|
+
recordType: fromWasmRecordType(decoded.exportRecordType()),
|
|
75
|
+
accountId: decoded.exportAcctNum(),
|
|
76
|
+
})
|
|
77
|
+
} catch (cause) {
|
|
78
|
+
if (cause instanceof GeeqError) throw cause
|
|
79
|
+
throw invalidAddress(`"${address}" is not a valid Geeq wallet address.`, cause)
|
|
80
|
+
} finally {
|
|
81
|
+
decoded?.free()
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Decode a base58 wallet address, loading the engine if needed. */
|
|
86
|
+
export async function decodeWalletAddress(address: string): Promise<DecodedWalletAddress> {
|
|
87
|
+
await initGeeq()
|
|
88
|
+
return decodeWalletAddressSync(address)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* True when `address` decodes as a Geeq wallet address. Requires a loaded engine.
|
|
93
|
+
*
|
|
94
|
+
* Throws `not-initialized` rather than answering before the engine has loaded: `false`
|
|
95
|
+
* would call every address invalid, including good ones.
|
|
96
|
+
*/
|
|
97
|
+
export function isValidWalletAddress(address: string): boolean {
|
|
98
|
+
try {
|
|
99
|
+
decodeWalletAddressSync(address)
|
|
100
|
+
return true
|
|
101
|
+
} catch (error) {
|
|
102
|
+
if (error instanceof GeeqError && error.code === 'not-initialized') throw error
|
|
103
|
+
return false
|
|
104
|
+
}
|
|
105
|
+
}
|
package/src/amount.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Uint64 } from 'capnp-ts'
|
|
2
|
+
|
|
3
|
+
import { invalidArgument } from './errors'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An amount of coin, with its unit stated.
|
|
7
|
+
*
|
|
8
|
+
* The protocol counts only **pennies**, as geeq_node_core calls them. A Geeq is a display
|
|
9
|
+
* unit, and how many pennies make one is not on the chain: the app says, as
|
|
10
|
+
* `penniesPerGeeq` when it connects, and every conversion takes it from there.
|
|
11
|
+
*
|
|
12
|
+
* Every amount crossing this SDK's surface names its unit, because the alternative is a
|
|
13
|
+
* bare number that means one thing to the caller and another to the chain. That mistake
|
|
14
|
+
* does not throw — it just moves the wrong amount.
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* { geeq: "12.34" } // human-facing: what someone typed
|
|
18
|
+
* { pennies: balance } // protocol-facing: as the chain counts it
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export type GeeqAmount = { readonly geeq: string | number } | { readonly pennies: bigint | number }
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @internal The decimal places in a Geeq: the zeros in `penniesPerGeeq`. It must be a
|
|
25
|
+
* power of ten, so that every amount of pennies has an exact decimal form.
|
|
26
|
+
*/
|
|
27
|
+
export function decimalsOf(penniesPerGeeq: bigint): number {
|
|
28
|
+
const text = typeof penniesPerGeeq === 'bigint' ? String(penniesPerGeeq) : ''
|
|
29
|
+
if (!/^10*$/u.test(text)) {
|
|
30
|
+
throw invalidArgument(
|
|
31
|
+
`penniesPerGeeq must be a bigint power of ten (1n, 10n, 100n, …), received ${String(penniesPerGeeq)}.`,
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
return text.length - 1
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Parse a decimal Geeq string into pennies. Rejects more precision than exists. */
|
|
38
|
+
function geeqToPennies(value: string | number, penniesPerGeeq: bigint): bigint {
|
|
39
|
+
const decimals = decimalsOf(penniesPerGeeq)
|
|
40
|
+
// Numbers go through their string form: 0.1 + 0.2 is not 0.3, and money written as a
|
|
41
|
+
// float has already lost whatever the float lost.
|
|
42
|
+
const text = typeof value === 'number' ? String(value) : value.trim()
|
|
43
|
+
|
|
44
|
+
if (typeof value === 'number' && !Number.isFinite(value)) {
|
|
45
|
+
throw invalidArgument(`An amount in geeq must be a finite number, received ${text}.`)
|
|
46
|
+
}
|
|
47
|
+
if (typeof value === 'number' && Number.isInteger(value) && !Number.isSafeInteger(value)) {
|
|
48
|
+
throw invalidArgument(
|
|
49
|
+
`${text} is too large to be exact as a JavaScript number, so it may not be what was ` +
|
|
50
|
+
'typed. Pass it as a string: { geeq: "…" }.',
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
if (text.startsWith('-')) {
|
|
54
|
+
throw invalidArgument(`An amount cannot be negative, received ${text}.`)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const match = /^(\d+)(?:\.(\d+))?$/u.exec(text)
|
|
58
|
+
if (match === null) {
|
|
59
|
+
throw invalidArgument(
|
|
60
|
+
`An amount in geeq must be a decimal number such as "12.34", received ${JSON.stringify(text)}.`,
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const whole = match[1] as string
|
|
65
|
+
const fraction = match[2] ?? ''
|
|
66
|
+
if (fraction.length > decimals) {
|
|
67
|
+
throw invalidArgument(
|
|
68
|
+
`${text} has ${fraction.length} decimal places, but at ${penniesPerGeeq} pennies to a ` +
|
|
69
|
+
`Geeq only ${decimals} are possible. Round it, or give the exact figure as { pennies }.`,
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
return BigInt(whole) * penniesPerGeeq + BigInt(fraction.padEnd(decimals, '0'))
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Resolve any {@link GeeqAmount} to pennies, the unit the protocol uses. A `{ geeq }`
|
|
77
|
+
* figure is read at `penniesPerGeeq` to the Geeq; `{ pennies }` is taken as it is.
|
|
78
|
+
*/
|
|
79
|
+
export function toPennies(amount: GeeqAmount, penniesPerGeeq: bigint): bigint {
|
|
80
|
+
if (amount !== null && typeof amount === 'object') {
|
|
81
|
+
if ('pennies' in amount) {
|
|
82
|
+
const { pennies } = amount
|
|
83
|
+
if (typeof pennies === 'bigint') {
|
|
84
|
+
if (pennies < 0n) throw invalidArgument(`An amount cannot be negative, received ${pennies}.`)
|
|
85
|
+
return pennies
|
|
86
|
+
}
|
|
87
|
+
if (typeof pennies === 'number') {
|
|
88
|
+
if (!Number.isInteger(pennies)) {
|
|
89
|
+
throw invalidArgument(
|
|
90
|
+
`An amount in pennies must be a whole number, received ${pennies}. Pennies are ` +
|
|
91
|
+
'already the smallest unit — there is nothing below them.',
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
// Above 2^53 a number has already been rounded to its nearest representable
|
|
95
|
+
// neighbour, so converting it would move a different amount from the one meant.
|
|
96
|
+
if (!Number.isSafeInteger(pennies)) {
|
|
97
|
+
throw invalidArgument(
|
|
98
|
+
`${pennies} pennies is too large to be exact as a JavaScript number. Pass it as ` +
|
|
99
|
+
'a bigint: { pennies: 123n }.',
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
if (pennies < 0) throw invalidArgument(`An amount cannot be negative, received ${pennies}.`)
|
|
103
|
+
return BigInt(pennies)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if ('geeq' in amount) return geeqToPennies(amount.geeq, penniesPerGeeq)
|
|
107
|
+
}
|
|
108
|
+
throw invalidArgument(
|
|
109
|
+
'An amount must name its unit: { geeq: "12.34" } or { pennies } as the chain counts them.',
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Format pennies as a decimal Geeq string at `penniesPerGeeq` to the Geeq, the way the Geeq
|
|
115
|
+
* wallet shows amounts: every place the unit has, trailing zeros dropped.
|
|
116
|
+
*
|
|
117
|
+
* A negative figure — a shortfall, say — keeps its sign: `-1.5`, not `-1.-5`.
|
|
118
|
+
*/
|
|
119
|
+
export function formatGeeq(pennies: bigint, penniesPerGeeq: bigint): string {
|
|
120
|
+
const decimals = decimalsOf(penniesPerGeeq)
|
|
121
|
+
// Split the magnitude, not the signed value: bigint division truncates toward zero, so
|
|
122
|
+
// both halves of a negative figure would carry the sign.
|
|
123
|
+
const sign = pennies < 0n ? '-' : ''
|
|
124
|
+
const magnitude = pennies < 0n ? -pennies : pennies
|
|
125
|
+
const whole = magnitude / penniesPerGeeq
|
|
126
|
+
const fraction = String(magnitude % penniesPerGeeq).padStart(decimals, '0').replace(/0+$/u, '')
|
|
127
|
+
return fraction === '' ? `${sign}${whole}` : `${sign}${whole}.${fraction}`
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** @internal Read a Cap'n Proto UInt64 as a bigint. Little-endian, as the protocol writes it. */
|
|
131
|
+
export function uint64ToPennies(value: Uint64): bigint {
|
|
132
|
+
return value.toDataView().getBigUint64(0, true)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** @internal Write pennies as a Cap'n Proto UInt64. */
|
|
136
|
+
export function penniesToUint64(pennies: bigint): Uint64 {
|
|
137
|
+
if (pennies < 0n || pennies > 0xffffffffffffffffn) {
|
|
138
|
+
throw invalidArgument(`An amount must fit in a uint64, received ${pennies} pennies.`)
|
|
139
|
+
}
|
|
140
|
+
const view = new DataView(new ArrayBuffer(8))
|
|
141
|
+
view.setBigUint64(0, pennies, true)
|
|
142
|
+
return Uint64.fromDataView(view)
|
|
143
|
+
}
|
package/src/assert.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { invalidArgument } from './errors'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Argument checks shared across layers. Each one names the argument and what it received,
|
|
5
|
+
* so the message points at the caller's data rather than at this file.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** The largest value the protocol's 32-bit fields hold: chain, block, node, nonce, index. */
|
|
11
|
+
export const MAX_UINT32 = 0xffffffff
|
|
12
|
+
|
|
13
|
+
/** @internal */
|
|
14
|
+
export function assertUint32(value: number, label: string): void {
|
|
15
|
+
if (!Number.isInteger(value) || value < 0 || value > MAX_UINT32) {
|
|
16
|
+
throw invalidArgument(
|
|
17
|
+
`${label} must be an integer between 0 and ${MAX_UINT32}, received ${String(value)}.`,
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** @internal An optional option in milliseconds. Undefined means "use the default". */
|
|
23
|
+
export function assertDuration(value: number | undefined, label: string): void {
|
|
24
|
+
if (value === undefined) return
|
|
25
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
26
|
+
throw invalidArgument(
|
|
27
|
+
`${label} must be a non-negative number of milliseconds, received ${String(value)}.`,
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Cap'n Proto schemas (vendored)
|
|
2
|
+
|
|
3
|
+
Generated TypeScript bindings for the Geeq protocol messages, copied verbatim from the
|
|
4
|
+
`generated/` directory of the private `geeq_capnp_ts` repository so the published SDK
|
|
5
|
+
depends on nothing outside the public npm registry.
|
|
6
|
+
|
|
7
|
+
| | |
|
|
8
|
+
|---|---|
|
|
9
|
+
| Source | `bitbucket.org/bigkraken5/geeq_capnp_ts`, branch `app-15` |
|
|
10
|
+
| Commit | `91c2ddd25d66b64019c78ddcb27157767e506d26` |
|
|
11
|
+
|
|
12
|
+
Do not edit these files by hand. To update, copy `generated/*.capnp.ts` from the new
|
|
13
|
+
commit over this directory, update the commit above, and run `npm run typecheck`,
|
|
14
|
+
`npm test` and `npm run build && npm run smoke`. The schemas must match the protocol
|
|
15
|
+
version of the WASM engine in `src/wasm`.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This file has been automatically generated by the [capnpc-ts utility](https://github.com/jdiaz5513/capnp-ts).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as capnp from "capnp-ts";
|
|
8
|
+
import { ObjectSize as __O, Struct as __S } from 'capnp-ts';
|
|
9
|
+
export const _capnpFileId = "a0821f452231cb39";
|
|
10
|
+
export enum AuditCode {
|
|
11
|
+
AUDIT_CODE_EQUIVOCATION,
|
|
12
|
+
AUDIT_CODE_HCS_CSV,
|
|
13
|
+
AUDIT_CODE_HUB_DISHONEST,
|
|
14
|
+
AUDIT_CODE_NCS_CSV,
|
|
15
|
+
AUDIT_CODE_NODE_DISHONEST,
|
|
16
|
+
AUDIT_CODE_RCS_CSV,
|
|
17
|
+
AUDIT_CODE_RELAY_DISHONEST
|
|
18
|
+
}
|
|
19
|
+
export class AuditAdminNetTx extends __S {
|
|
20
|
+
static readonly _capnp = { displayName: "AuditAdminNetTx", id: "b7d1c71a0cf819b7", size: new __O(16, 1) };
|
|
21
|
+
getAmtCoin(): capnp.Uint64 { return __S.getUint64(0, this); }
|
|
22
|
+
setAmtCoin(value: capnp.Uint64): void { __S.setUint64(0, value, this); }
|
|
23
|
+
getNodeNum(): number { return __S.getUint32(8, this); }
|
|
24
|
+
setNodeNum(value: number): void { __S.setUint32(8, value, this); }
|
|
25
|
+
getAuditCode(): AuditCode { return __S.getUint16(12, this); }
|
|
26
|
+
setAuditCode(value: AuditCode): void { __S.setUint16(12, value, this); }
|
|
27
|
+
adoptAcctNumSend(value: capnp.Orphan<capnp.Data>): void { __S.adopt(value, __S.getPointer(0, this)); }
|
|
28
|
+
disownAcctNumSend(): capnp.Orphan<capnp.Data> { return __S.disown(this.getAcctNumSend()); }
|
|
29
|
+
getAcctNumSend(): capnp.Data { return __S.getData(0, this); }
|
|
30
|
+
hasAcctNumSend(): boolean { return !__S.isNull(__S.getPointer(0, this)); }
|
|
31
|
+
initAcctNumSend(length: number): capnp.Data { return __S.initData(0, length, this); }
|
|
32
|
+
setAcctNumSend(value: capnp.Data): void { __S.copyFrom(value, __S.getPointer(0, this)); }
|
|
33
|
+
toString(): string { return "AuditAdminNetTx_" + super.toString(); }
|
|
34
|
+
}
|
|
35
|
+
export class FeeDistAdminNetTx extends __S {
|
|
36
|
+
static readonly _capnp = { displayName: "FeeDistAdminNetTx", id: "da1ade52d59dba3b", size: new __O(16, 1) };
|
|
37
|
+
getAmtCoin(): capnp.Uint64 { return __S.getUint64(0, this); }
|
|
38
|
+
setAmtCoin(value: capnp.Uint64): void { __S.setUint64(0, value, this); }
|
|
39
|
+
getNodeNum(): number { return __S.getUint32(8, this); }
|
|
40
|
+
setNodeNum(value: number): void { __S.setUint32(8, value, this); }
|
|
41
|
+
adoptAcctNumRcv(value: capnp.Orphan<capnp.Data>): void { __S.adopt(value, __S.getPointer(0, this)); }
|
|
42
|
+
disownAcctNumRcv(): capnp.Orphan<capnp.Data> { return __S.disown(this.getAcctNumRcv()); }
|
|
43
|
+
getAcctNumRcv(): capnp.Data { return __S.getData(0, this); }
|
|
44
|
+
hasAcctNumRcv(): boolean { return !__S.isNull(__S.getPointer(0, this)); }
|
|
45
|
+
initAcctNumRcv(length: number): capnp.Data { return __S.initData(0, length, this); }
|
|
46
|
+
setAcctNumRcv(value: capnp.Data): void { __S.copyFrom(value, __S.getPointer(0, this)); }
|
|
47
|
+
toString(): string { return "FeeDistAdminNetTx_" + super.toString(); }
|
|
48
|
+
}
|
|
49
|
+
export class RfdAdminNetTx extends __S {
|
|
50
|
+
static readonly _capnp = { displayName: "RfdAdminNetTx", id: "cab22a89a36ebee1", size: new __O(8, 2) };
|
|
51
|
+
getAmtCoin(): capnp.Uint64 { return __S.getUint64(0, this); }
|
|
52
|
+
setAmtCoin(value: capnp.Uint64): void { __S.setUint64(0, value, this); }
|
|
53
|
+
adoptAcctNumSend(value: capnp.Orphan<capnp.Data>): void { __S.adopt(value, __S.getPointer(0, this)); }
|
|
54
|
+
disownAcctNumSend(): capnp.Orphan<capnp.Data> { return __S.disown(this.getAcctNumSend()); }
|
|
55
|
+
getAcctNumSend(): capnp.Data { return __S.getData(0, this); }
|
|
56
|
+
hasAcctNumSend(): boolean { return !__S.isNull(__S.getPointer(0, this)); }
|
|
57
|
+
initAcctNumSend(length: number): capnp.Data { return __S.initData(0, length, this); }
|
|
58
|
+
setAcctNumSend(value: capnp.Data): void { __S.copyFrom(value, __S.getPointer(0, this)); }
|
|
59
|
+
adoptAcctNumRcv(value: capnp.Orphan<capnp.Data>): void { __S.adopt(value, __S.getPointer(1, this)); }
|
|
60
|
+
disownAcctNumRcv(): capnp.Orphan<capnp.Data> { return __S.disown(this.getAcctNumRcv()); }
|
|
61
|
+
getAcctNumRcv(): capnp.Data { return __S.getData(1, this); }
|
|
62
|
+
hasAcctNumRcv(): boolean { return !__S.isNull(__S.getPointer(1, this)); }
|
|
63
|
+
initAcctNumRcv(length: number): capnp.Data { return __S.initData(1, length, this); }
|
|
64
|
+
setAcctNumRcv(value: capnp.Data): void { __S.copyFrom(value, __S.getPointer(1, this)); }
|
|
65
|
+
toString(): string { return "RfdAdminNetTx_" + super.toString(); }
|
|
66
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This file has been automatically generated by the [capnpc-ts utility](https://github.com/jdiaz5513/capnp-ts).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as capnp from "capnp-ts";
|
|
8
|
+
import { ObjectSize as __O, Struct as __S } from 'capnp-ts';
|
|
9
|
+
import { NodePayloadList } from "./nodePayloadList.capnp";
|
|
10
|
+
export const _capnpFileId = "c58bc266447b8f2d";
|
|
11
|
+
export class AppLayBlock extends __S {
|
|
12
|
+
static readonly _capnp = { displayName: "AppLayBlock", id: "e47b52b5ebbd566c", size: new __O(8, 1) };
|
|
13
|
+
static _NodePayloadLists: capnp.ListCtor<NodePayloadList>;
|
|
14
|
+
getBlockNum(): number { return __S.getUint32(0, this); }
|
|
15
|
+
setBlockNum(value: number): void { __S.setUint32(0, value, this); }
|
|
16
|
+
getChainNum(): number { return __S.getUint32(4, this); }
|
|
17
|
+
setChainNum(value: number): void { __S.setUint32(4, value, this); }
|
|
18
|
+
adoptNodePayloadLists(value: capnp.Orphan<capnp.List<NodePayloadList>>): void { __S.adopt(value, __S.getPointer(0, this)); }
|
|
19
|
+
disownNodePayloadLists(): capnp.Orphan<capnp.List<NodePayloadList>> { return __S.disown(this.getNodePayloadLists()); }
|
|
20
|
+
getNodePayloadLists(): capnp.List<NodePayloadList> { return __S.getList(0, AppLayBlock._NodePayloadLists, this); }
|
|
21
|
+
hasNodePayloadLists(): boolean { return !__S.isNull(__S.getPointer(0, this)); }
|
|
22
|
+
initNodePayloadLists(length: number): capnp.List<NodePayloadList> { return __S.initList(0, AppLayBlock._NodePayloadLists, length, this); }
|
|
23
|
+
setNodePayloadLists(value: capnp.List<NodePayloadList>): void { __S.copyFrom(value, __S.getPointer(0, this)); }
|
|
24
|
+
toString(): string { return "AppLayBlock_" + super.toString(); }
|
|
25
|
+
}
|
|
26
|
+
AppLayBlock._NodePayloadLists = capnp.CompositeList(NodePayloadList);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This file has been automatically generated by the [capnpc-ts utility](https://github.com/jdiaz5513/capnp-ts).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as capnp from "capnp-ts";
|
|
8
|
+
import { ObjectSize as __O, Struct as __S } from 'capnp-ts';
|
|
9
|
+
import { AppCounterpartyRec, AppDceRec, AppNftRec, AppStackableRec, AppLayRec } from "./appLayRec.capnp";
|
|
10
|
+
import { ByteString } from "./misc.capnp";
|
|
11
|
+
export const _capnpFileId = "a45ad15476ce444c";
|
|
12
|
+
export class AppLayLedger extends __S {
|
|
13
|
+
static readonly _capnp = { displayName: "AppLayLedger", id: "93328856bc57f4b3", size: new __O(8, 2) };
|
|
14
|
+
static _TokenNames: capnp.ListCtor<ByteString>;
|
|
15
|
+
static _AppLayRecs: capnp.ListCtor<AppLayRec>;
|
|
16
|
+
getBlockNum(): number { return __S.getUint32(0, this); }
|
|
17
|
+
setBlockNum(value: number): void { __S.setUint32(0, value, this); }
|
|
18
|
+
getChainNum(): number { return __S.getUint32(4, this); }
|
|
19
|
+
setChainNum(value: number): void { __S.setUint32(4, value, this); }
|
|
20
|
+
adoptTokenNames(value: capnp.Orphan<capnp.List<ByteString>>): void { __S.adopt(value, __S.getPointer(0, this)); }
|
|
21
|
+
disownTokenNames(): capnp.Orphan<capnp.List<ByteString>> { return __S.disown(this.getTokenNames()); }
|
|
22
|
+
getTokenNames(): capnp.List<ByteString> { return __S.getList(0, AppLayLedger._TokenNames, this); }
|
|
23
|
+
hasTokenNames(): boolean { return !__S.isNull(__S.getPointer(0, this)); }
|
|
24
|
+
initTokenNames(length: number): capnp.List<ByteString> { return __S.initList(0, AppLayLedger._TokenNames, length, this); }
|
|
25
|
+
setTokenNames(value: capnp.List<ByteString>): void { __S.copyFrom(value, __S.getPointer(0, this)); }
|
|
26
|
+
adoptAppLayRecs(value: capnp.Orphan<capnp.List<AppLayRec>>): void { __S.adopt(value, __S.getPointer(1, this)); }
|
|
27
|
+
disownAppLayRecs(): capnp.Orphan<capnp.List<AppLayRec>> { return __S.disown(this.getAppLayRecs()); }
|
|
28
|
+
getAppLayRecs(): capnp.List<AppLayRec> { return __S.getList(1, AppLayLedger._AppLayRecs, this); }
|
|
29
|
+
hasAppLayRecs(): boolean { return !__S.isNull(__S.getPointer(1, this)); }
|
|
30
|
+
initAppLayRecs(length: number): capnp.List<AppLayRec> { return __S.initList(1, AppLayLedger._AppLayRecs, length, this); }
|
|
31
|
+
setAppLayRecs(value: capnp.List<AppLayRec>): void { __S.copyFrom(value, __S.getPointer(1, this)); }
|
|
32
|
+
toString(): string { return "AppLayLedger_" + super.toString(); }
|
|
33
|
+
}
|
|
34
|
+
AppLayLedger._TokenNames = capnp.CompositeList(ByteString);
|
|
35
|
+
AppLayLedger._AppLayRecs = capnp.CompositeList(AppLayRec);
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This file has been automatically generated by the [capnpc-ts utility](https://github.com/jdiaz5513/capnp-ts).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as capnp from "capnp-ts";
|
|
8
|
+
import { ObjectSize as __O, Struct as __S } from 'capnp-ts';
|
|
9
|
+
import { MetadataEntry, AttestationSubgroupData, AttestationSubgroup } from "./payload.capnp";
|
|
10
|
+
export const _capnpFileId = "9ec3746dd61302cf";
|
|
11
|
+
export class AppCounterpartyRec extends __S {
|
|
12
|
+
static readonly _capnp = { displayName: "AppCounterpartyRec", id: "af4fb7d47ed69ca8", size: new __O(0, 1) };
|
|
13
|
+
static _AttestationSubgroups: capnp.ListCtor<AttestationSubgroup>;
|
|
14
|
+
adoptAttestationSubgroups(value: capnp.Orphan<capnp.List<AttestationSubgroup>>): void { __S.adopt(value, __S.getPointer(0, this)); }
|
|
15
|
+
disownAttestationSubgroups(): capnp.Orphan<capnp.List<AttestationSubgroup>> { return __S.disown(this.getAttestationSubgroups()); }
|
|
16
|
+
getAttestationSubgroups(): capnp.List<AttestationSubgroup> { return __S.getList(0, AppCounterpartyRec._AttestationSubgroups, this); }
|
|
17
|
+
hasAttestationSubgroups(): boolean { return !__S.isNull(__S.getPointer(0, this)); }
|
|
18
|
+
initAttestationSubgroups(length: number): capnp.List<AttestationSubgroup> { return __S.initList(0, AppCounterpartyRec._AttestationSubgroups, length, this); }
|
|
19
|
+
setAttestationSubgroups(value: capnp.List<AttestationSubgroup>): void { __S.copyFrom(value, __S.getPointer(0, this)); }
|
|
20
|
+
toString(): string { return "AppCounterpartyRec_" + super.toString(); }
|
|
21
|
+
}
|
|
22
|
+
export class AppDceRec extends __S {
|
|
23
|
+
static readonly _capnp = { displayName: "AppDceRec", id: "bf9343b8032d56c5", size: new __O(0, 1) };
|
|
24
|
+
static _AttestationSubgroups: capnp.ListCtor<AttestationSubgroup>;
|
|
25
|
+
adoptAttestationSubgroups(value: capnp.Orphan<capnp.List<AttestationSubgroup>>): void { __S.adopt(value, __S.getPointer(0, this)); }
|
|
26
|
+
disownAttestationSubgroups(): capnp.Orphan<capnp.List<AttestationSubgroup>> { return __S.disown(this.getAttestationSubgroups()); }
|
|
27
|
+
getAttestationSubgroups(): capnp.List<AttestationSubgroup> { return __S.getList(0, AppDceRec._AttestationSubgroups, this); }
|
|
28
|
+
hasAttestationSubgroups(): boolean { return !__S.isNull(__S.getPointer(0, this)); }
|
|
29
|
+
initAttestationSubgroups(length: number): capnp.List<AttestationSubgroup> { return __S.initList(0, AppDceRec._AttestationSubgroups, length, this); }
|
|
30
|
+
setAttestationSubgroups(value: capnp.List<AttestationSubgroup>): void { __S.copyFrom(value, __S.getPointer(0, this)); }
|
|
31
|
+
toString(): string { return "AppDceRec_" + super.toString(); }
|
|
32
|
+
}
|
|
33
|
+
export class AppNftRec extends __S {
|
|
34
|
+
static readonly _capnp = { displayName: "AppNftRec", id: "fbc6ff8babb8c50a", size: new __O(0, 1) };
|
|
35
|
+
adoptAttestationSubgroup(value: capnp.Orphan<AttestationSubgroup>): void { __S.adopt(value, __S.getPointer(0, this)); }
|
|
36
|
+
disownAttestationSubgroup(): capnp.Orphan<AttestationSubgroup> { return __S.disown(this.getAttestationSubgroup()); }
|
|
37
|
+
getAttestationSubgroup(): AttestationSubgroup { return __S.getStruct(0, AttestationSubgroup, this); }
|
|
38
|
+
hasAttestationSubgroup(): boolean { return !__S.isNull(__S.getPointer(0, this)); }
|
|
39
|
+
initAttestationSubgroup(): AttestationSubgroup { return __S.initStructAt(0, AttestationSubgroup, this); }
|
|
40
|
+
setAttestationSubgroup(value: AttestationSubgroup): void { __S.copyFrom(value, __S.getPointer(0, this)); }
|
|
41
|
+
toString(): string { return "AppNftRec_" + super.toString(); }
|
|
42
|
+
}
|
|
43
|
+
export class AppStackableRec extends __S {
|
|
44
|
+
static readonly _capnp = { displayName: "AppStackableRec", id: "cdd062ed7d86209c", size: new __O(0, 1) };
|
|
45
|
+
static _AttestationSubgroups: capnp.ListCtor<AttestationSubgroup>;
|
|
46
|
+
adoptAttestationSubgroups(value: capnp.Orphan<capnp.List<AttestationSubgroup>>): void { __S.adopt(value, __S.getPointer(0, this)); }
|
|
47
|
+
disownAttestationSubgroups(): capnp.Orphan<capnp.List<AttestationSubgroup>> { return __S.disown(this.getAttestationSubgroups()); }
|
|
48
|
+
getAttestationSubgroups(): capnp.List<AttestationSubgroup> { return __S.getList(0, AppStackableRec._AttestationSubgroups, this); }
|
|
49
|
+
hasAttestationSubgroups(): boolean { return !__S.isNull(__S.getPointer(0, this)); }
|
|
50
|
+
initAttestationSubgroups(length: number): capnp.List<AttestationSubgroup> { return __S.initList(0, AppStackableRec._AttestationSubgroups, length, this); }
|
|
51
|
+
setAttestationSubgroups(value: capnp.List<AttestationSubgroup>): void { __S.copyFrom(value, __S.getPointer(0, this)); }
|
|
52
|
+
toString(): string { return "AppStackableRec_" + super.toString(); }
|
|
53
|
+
}
|
|
54
|
+
export enum AppLayRec_RecType_Which {
|
|
55
|
+
COUNTERPARTY = 0,
|
|
56
|
+
DCE = 1,
|
|
57
|
+
NFT = 2,
|
|
58
|
+
STACKABLE = 3
|
|
59
|
+
}
|
|
60
|
+
export class AppLayRec_RecType extends __S {
|
|
61
|
+
static readonly COUNTERPARTY = AppLayRec_RecType_Which.COUNTERPARTY;
|
|
62
|
+
static readonly DCE = AppLayRec_RecType_Which.DCE;
|
|
63
|
+
static readonly NFT = AppLayRec_RecType_Which.NFT;
|
|
64
|
+
static readonly STACKABLE = AppLayRec_RecType_Which.STACKABLE;
|
|
65
|
+
static readonly _capnp = { displayName: "recType", id: "b322cc20c9120cdb", size: new __O(8, 2) };
|
|
66
|
+
adoptCounterparty(value: capnp.Orphan<AppCounterpartyRec>): void {
|
|
67
|
+
__S.setUint16(0, 0, this);
|
|
68
|
+
__S.adopt(value, __S.getPointer(0, this));
|
|
69
|
+
}
|
|
70
|
+
disownCounterparty(): capnp.Orphan<AppCounterpartyRec> { return __S.disown(this.getCounterparty()); }
|
|
71
|
+
getCounterparty(): AppCounterpartyRec {
|
|
72
|
+
__S.testWhich("counterparty", __S.getUint16(0, this), 0, this);
|
|
73
|
+
return __S.getStruct(0, AppCounterpartyRec, this);
|
|
74
|
+
}
|
|
75
|
+
hasCounterparty(): boolean { return !__S.isNull(__S.getPointer(0, this)); }
|
|
76
|
+
initCounterparty(): AppCounterpartyRec {
|
|
77
|
+
__S.setUint16(0, 0, this);
|
|
78
|
+
return __S.initStructAt(0, AppCounterpartyRec, this);
|
|
79
|
+
}
|
|
80
|
+
isCounterparty(): boolean { return __S.getUint16(0, this) === 0; }
|
|
81
|
+
setCounterparty(value: AppCounterpartyRec): void {
|
|
82
|
+
__S.setUint16(0, 0, this);
|
|
83
|
+
__S.copyFrom(value, __S.getPointer(0, this));
|
|
84
|
+
}
|
|
85
|
+
adoptDce(value: capnp.Orphan<AppDceRec>): void {
|
|
86
|
+
__S.setUint16(0, 1, this);
|
|
87
|
+
__S.adopt(value, __S.getPointer(0, this));
|
|
88
|
+
}
|
|
89
|
+
disownDce(): capnp.Orphan<AppDceRec> { return __S.disown(this.getDce()); }
|
|
90
|
+
getDce(): AppDceRec {
|
|
91
|
+
__S.testWhich("dce", __S.getUint16(0, this), 1, this);
|
|
92
|
+
return __S.getStruct(0, AppDceRec, this);
|
|
93
|
+
}
|
|
94
|
+
hasDce(): boolean { return !__S.isNull(__S.getPointer(0, this)); }
|
|
95
|
+
initDce(): AppDceRec {
|
|
96
|
+
__S.setUint16(0, 1, this);
|
|
97
|
+
return __S.initStructAt(0, AppDceRec, this);
|
|
98
|
+
}
|
|
99
|
+
isDce(): boolean { return __S.getUint16(0, this) === 1; }
|
|
100
|
+
setDce(value: AppDceRec): void {
|
|
101
|
+
__S.setUint16(0, 1, this);
|
|
102
|
+
__S.copyFrom(value, __S.getPointer(0, this));
|
|
103
|
+
}
|
|
104
|
+
adoptNft(value: capnp.Orphan<AppNftRec>): void {
|
|
105
|
+
__S.setUint16(0, 2, this);
|
|
106
|
+
__S.adopt(value, __S.getPointer(0, this));
|
|
107
|
+
}
|
|
108
|
+
disownNft(): capnp.Orphan<AppNftRec> { return __S.disown(this.getNft()); }
|
|
109
|
+
getNft(): AppNftRec {
|
|
110
|
+
__S.testWhich("nft", __S.getUint16(0, this), 2, this);
|
|
111
|
+
return __S.getStruct(0, AppNftRec, this);
|
|
112
|
+
}
|
|
113
|
+
hasNft(): boolean { return !__S.isNull(__S.getPointer(0, this)); }
|
|
114
|
+
initNft(): AppNftRec {
|
|
115
|
+
__S.setUint16(0, 2, this);
|
|
116
|
+
return __S.initStructAt(0, AppNftRec, this);
|
|
117
|
+
}
|
|
118
|
+
isNft(): boolean { return __S.getUint16(0, this) === 2; }
|
|
119
|
+
setNft(value: AppNftRec): void {
|
|
120
|
+
__S.setUint16(0, 2, this);
|
|
121
|
+
__S.copyFrom(value, __S.getPointer(0, this));
|
|
122
|
+
}
|
|
123
|
+
adoptStackable(value: capnp.Orphan<AppStackableRec>): void {
|
|
124
|
+
__S.setUint16(0, 3, this);
|
|
125
|
+
__S.adopt(value, __S.getPointer(0, this));
|
|
126
|
+
}
|
|
127
|
+
disownStackable(): capnp.Orphan<AppStackableRec> { return __S.disown(this.getStackable()); }
|
|
128
|
+
getStackable(): AppStackableRec {
|
|
129
|
+
__S.testWhich("stackable", __S.getUint16(0, this), 3, this);
|
|
130
|
+
return __S.getStruct(0, AppStackableRec, this);
|
|
131
|
+
}
|
|
132
|
+
hasStackable(): boolean { return !__S.isNull(__S.getPointer(0, this)); }
|
|
133
|
+
initStackable(): AppStackableRec {
|
|
134
|
+
__S.setUint16(0, 3, this);
|
|
135
|
+
return __S.initStructAt(0, AppStackableRec, this);
|
|
136
|
+
}
|
|
137
|
+
isStackable(): boolean { return __S.getUint16(0, this) === 3; }
|
|
138
|
+
setStackable(value: AppStackableRec): void {
|
|
139
|
+
__S.setUint16(0, 3, this);
|
|
140
|
+
__S.copyFrom(value, __S.getPointer(0, this));
|
|
141
|
+
}
|
|
142
|
+
toString(): string { return "AppLayRec_RecType_" + super.toString(); }
|
|
143
|
+
which(): AppLayRec_RecType_Which { return __S.getUint16(0, this); }
|
|
144
|
+
}
|
|
145
|
+
export class AppLayRec extends __S {
|
|
146
|
+
static readonly _capnp = { displayName: "AppLayRec", id: "ea6a5049023b7473", size: new __O(8, 2) };
|
|
147
|
+
getRecType(): AppLayRec_RecType { return __S.getAs(AppLayRec_RecType, this); }
|
|
148
|
+
initRecType(): AppLayRec_RecType { return __S.getAs(AppLayRec_RecType, this); }
|
|
149
|
+
adoptAcctNumApp(value: capnp.Orphan<capnp.Data>): void { __S.adopt(value, __S.getPointer(1, this)); }
|
|
150
|
+
disownAcctNumApp(): capnp.Orphan<capnp.Data> { return __S.disown(this.getAcctNumApp()); }
|
|
151
|
+
getAcctNumApp(): capnp.Data { return __S.getData(1, this); }
|
|
152
|
+
hasAcctNumApp(): boolean { return !__S.isNull(__S.getPointer(1, this)); }
|
|
153
|
+
initAcctNumApp(length: number): capnp.Data { return __S.initData(1, length, this); }
|
|
154
|
+
setAcctNumApp(value: capnp.Data): void { __S.copyFrom(value, __S.getPointer(1, this)); }
|
|
155
|
+
toString(): string { return "AppLayRec_" + super.toString(); }
|
|
156
|
+
}
|
|
157
|
+
AppCounterpartyRec._AttestationSubgroups = capnp.CompositeList(AttestationSubgroup);
|
|
158
|
+
AppDceRec._AttestationSubgroups = capnp.CompositeList(AttestationSubgroup);
|
|
159
|
+
AppStackableRec._AttestationSubgroups = capnp.CompositeList(AttestationSubgroup);
|