@mem-cash/electrum 0.0.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/README.md +143 -0
- package/dist/address.d.ts +20 -0
- package/dist/address.d.ts.map +1 -0
- package/dist/address.js +51 -0
- package/dist/address.js.map +1 -0
- package/dist/dispatch.d.ts +18 -0
- package/dist/dispatch.d.ts.map +1 -0
- package/dist/dispatch.js +108 -0
- package/dist/dispatch.js.map +1 -0
- package/dist/headers.d.ts +14 -0
- package/dist/headers.d.ts.map +1 -0
- package/dist/headers.js +156 -0
- package/dist/headers.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/indexer.d.ts +42 -0
- package/dist/indexer.d.ts.map +1 -0
- package/dist/indexer.js +216 -0
- package/dist/indexer.js.map +1 -0
- package/dist/memCash.d.ts +40 -0
- package/dist/memCash.d.ts.map +1 -0
- package/dist/memCash.js +212 -0
- package/dist/memCash.js.map +1 -0
- package/dist/mempool.d.ts +6 -0
- package/dist/mempool.d.ts.map +1 -0
- package/dist/mempool.js +46 -0
- package/dist/mempool.js.map +1 -0
- package/dist/schema.d.ts +638 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +3 -0
- package/dist/schema.js.map +1 -0
- package/dist/scripthash.d.ts +18 -0
- package/dist/scripthash.d.ts.map +1 -0
- package/dist/scripthash.js +164 -0
- package/dist/scripthash.js.map +1 -0
- package/dist/server.d.ts +20 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +120 -0
- package/dist/server.js.map +1 -0
- package/dist/stubs.d.ts +12 -0
- package/dist/stubs.d.ts.map +1 -0
- package/dist/stubs.js +16 -0
- package/dist/stubs.js.map +1 -0
- package/dist/test.d.ts +8 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +240 -0
- package/dist/test.js.map +1 -0
- package/dist/testUtils.d.ts +20 -0
- package/dist/testUtils.d.ts.map +1 -0
- package/dist/testUtils.js +29 -0
- package/dist/testUtils.js.map +1 -0
- package/dist/transaction.d.ts +28 -0
- package/dist/transaction.d.ts.map +1 -0
- package/dist/transaction.js +318 -0
- package/dist/transaction.js.map +1 -0
- package/dist/transport.d.ts +24 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +16 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +85 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +58 -0
- package/dist/types.js.map +1 -0
- package/dist/utxo.d.ts +4 -0
- package/dist/utxo.d.ts.map +1 -0
- package/dist/utxo.js +39 -0
- package/dist/utxo.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Token data for a UTXO. */
|
|
2
|
+
export interface TokenDetails {
|
|
3
|
+
amount: bigint;
|
|
4
|
+
category: string;
|
|
5
|
+
nft?: {
|
|
6
|
+
capability: "none" | "mutable" | "minting";
|
|
7
|
+
commitment: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/** A UTXO with identifying outpoint, value, and optional token data. */
|
|
11
|
+
export interface Utxo {
|
|
12
|
+
txid: string;
|
|
13
|
+
vout: number;
|
|
14
|
+
satoshis: bigint;
|
|
15
|
+
token?: TokenDetails;
|
|
16
|
+
}
|
|
17
|
+
export declare const randomUtxo: (defaults?: Partial<Utxo>) => Utxo;
|
|
18
|
+
export declare const randomToken: (defaults?: Partial<TokenDetails>) => TokenDetails;
|
|
19
|
+
export declare const randomNFT: (defaults?: Partial<TokenDetails>) => TokenDetails;
|
|
20
|
+
//# sourceMappingURL=testUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testUtils.d.ts","sourceRoot":"","sources":["../src/testUtils.ts"],"names":[],"mappings":"AAEA,6BAA6B;AAC7B,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE;QACL,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;QAC3C,UAAU,EAAE,MAAM,CAAC;KACnB,CAAC;CACF;AAED,wEAAwE;AACxE,MAAM,WAAW,IAAI;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,YAAY,CAAC;CACrB;AAID,eAAO,MAAM,UAAU,GAAI,WAAW,OAAO,CAAC,IAAI,CAAC,KAAG,IAOpD,CAAC;AAEH,eAAO,MAAM,WAAW,GAAI,WAAW,OAAO,CAAC,YAAY,CAAC,KAAG,YAM7D,CAAC;AAEH,eAAO,MAAM,SAAS,GAAI,WAAW,OAAO,CAAC,YAAY,CAAC,KAAG,YAU3D,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { bigIntToVmNumber, binToHex, NonFungibleTokenCapability, sha256 } from "@bitauth/libauth";
|
|
2
|
+
const randomInt = () => BigInt(Math.floor(Math.random() * 10000));
|
|
3
|
+
export const randomUtxo = (defaults) => ({
|
|
4
|
+
...{
|
|
5
|
+
txid: binToHex(sha256.hash(bigIntToVmNumber(randomInt()))),
|
|
6
|
+
vout: Math.floor(Math.random() * 10),
|
|
7
|
+
satoshis: 100000n + randomInt(),
|
|
8
|
+
},
|
|
9
|
+
...defaults,
|
|
10
|
+
});
|
|
11
|
+
export const randomToken = (defaults) => ({
|
|
12
|
+
...{
|
|
13
|
+
category: binToHex(sha256.hash(bigIntToVmNumber(randomInt()))),
|
|
14
|
+
amount: 100000n + randomInt(),
|
|
15
|
+
},
|
|
16
|
+
...defaults,
|
|
17
|
+
});
|
|
18
|
+
export const randomNFT = (defaults) => ({
|
|
19
|
+
...{
|
|
20
|
+
category: binToHex(sha256.hash(bigIntToVmNumber(randomInt()))),
|
|
21
|
+
amount: 0n,
|
|
22
|
+
nft: {
|
|
23
|
+
commitment: binToHex(sha256.hash(bigIntToVmNumber(randomInt()))).slice(0, 8),
|
|
24
|
+
capability: NonFungibleTokenCapability.none,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
...defaults,
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=testUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testUtils.js","sourceRoot":"","sources":["../src/testUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,0BAA0B,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAoBlG,MAAM,SAAS,GAAG,GAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;AAE1E,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,QAAwB,EAAQ,EAAE,CAAC,CAAC;IAC9D,GAAG;QACF,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QAC1D,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC;QACpC,QAAQ,EAAE,OAAQ,GAAG,SAAS,EAAE;KAChC;IACD,GAAG,QAAQ;CACX,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,QAAgC,EAAgB,EAAE,CAAC,CAAC;IAC/E,GAAG;QACF,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QAC9D,MAAM,EAAE,OAAQ,GAAG,SAAS,EAAE;KAC9B;IACD,GAAG,QAAQ;CACX,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,QAAgC,EAAgB,EAAE,CAAC,CAAC;IAC7E,GAAG;QACF,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QAC9D,MAAM,EAAE,EAAE;QACV,GAAG,EAAE;YACJ,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;YAC5E,UAAU,EAAE,0BAA0B,CAAC,IAAI;SAC3C;KACD;IACD,GAAG,QAAQ;CACX,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type HandlerResult, type ProtocolContext } from "./types.js";
|
|
2
|
+
/** blockchain.transaction.get */
|
|
3
|
+
export declare function get(ctx: ProtocolContext, params: unknown[]): HandlerResult;
|
|
4
|
+
/** blockchain.transaction.get_merkle */
|
|
5
|
+
export declare function getMerkle(ctx: ProtocolContext, params: unknown[]): HandlerResult;
|
|
6
|
+
/** blockchain.transaction.id_from_pos */
|
|
7
|
+
export declare function idFromPos(ctx: ProtocolContext, params: unknown[]): HandlerResult;
|
|
8
|
+
/** blockchain.transaction.broadcast */
|
|
9
|
+
export declare function broadcast(ctx: ProtocolContext, params: unknown[]): HandlerResult;
|
|
10
|
+
/** blockchain.transaction.get_height */
|
|
11
|
+
export declare function getHeight(ctx: ProtocolContext, params: unknown[]): HandlerResult;
|
|
12
|
+
/** blockchain.transaction.get_confirmed_blockhash */
|
|
13
|
+
export declare function getConfirmedBlockhash(ctx: ProtocolContext, params: unknown[]): HandlerResult;
|
|
14
|
+
/** blockchain.transaction.dsproof.get */
|
|
15
|
+
export declare function dsproofGet(ctx: ProtocolContext, params: unknown[]): HandlerResult;
|
|
16
|
+
/** blockchain.transaction.dsproof.list */
|
|
17
|
+
export declare function dsproofList(ctx: ProtocolContext, _params: unknown[]): HandlerResult;
|
|
18
|
+
/** blockchain.transaction.broadcast_package */
|
|
19
|
+
export declare function broadcastPackage(ctx: ProtocolContext, params: unknown[]): HandlerResult;
|
|
20
|
+
/** blockchain.transaction.subscribe — returns current confirmation status. */
|
|
21
|
+
export declare function txSubscribe(ctx: ProtocolContext, params: unknown[]): HandlerResult;
|
|
22
|
+
/** blockchain.transaction.unsubscribe */
|
|
23
|
+
export declare function txUnsubscribe(_ctx: ProtocolContext, params: unknown[]): HandlerResult;
|
|
24
|
+
/** blockchain.transaction.dsproof.subscribe — returns current dsproof status. */
|
|
25
|
+
export declare function dsproofSubscribe(ctx: ProtocolContext, params: unknown[]): HandlerResult;
|
|
26
|
+
/** blockchain.transaction.dsproof.unsubscribe */
|
|
27
|
+
export declare function dsproofUnsubscribe(_ctx: ProtocolContext, params: unknown[]): HandlerResult;
|
|
28
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAQA,OAAO,EAKN,KAAK,aAAa,EAGlB,KAAK,eAAe,EAIpB,MAAM,YAAY,CAAC;AAEpB,iCAAiC;AACjC,wBAAgB,GAAG,CAAC,GAAG,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAqI1E;AAED,wCAAwC;AACxC,wBAAgB,SAAS,CAAC,GAAG,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAuChF;AAED,yCAAyC;AACzC,wBAAgB,SAAS,CAAC,GAAG,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAqChF;AAED,uCAAuC;AACvC,wBAAgB,SAAS,CAAC,GAAG,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAahF;AAED,wCAAwC;AACxC,wBAAgB,SAAS,CAAC,GAAG,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAahF;AAED,qDAAqD;AACrD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CA6B5F;AAED,yCAAyC;AACzC,wBAAgB,UAAU,CAAC,GAAG,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAIjF;AAED,0CAA0C;AAC1C,wBAAgB,WAAW,CAAC,GAAG,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,aAAa,CAEnF;AAKD,+CAA+C;AAC/C,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAuBvF;AAED,8EAA8E;AAC9E,wBAAgB,WAAW,CAAC,GAAG,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAgBlF;AAED,yCAAyC;AACzC,wBAAgB,aAAa,CAAC,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAIrF;AAED,iFAAiF;AACjF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAMvF;AAED,iDAAiD;AACjD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAI1F"}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { binToHex, decodeTransactionBch, hexToBin, isHex, lockingBytecodeToCashAddress, } from "@bitauth/libauth";
|
|
2
|
+
import { computeTxMerkleBranch } from "@mem-cash/types";
|
|
3
|
+
import { ERR_BAD_REQUEST, ERR_DAEMON_ERROR, ERR_INTERNAL, err, invalidParams, ok, validateNonNegativeInt, validateOptionalBool, validateTxid, } from "./types.js";
|
|
4
|
+
/** blockchain.transaction.get */
|
|
5
|
+
export function get(ctx, params) {
|
|
6
|
+
const txid = validateTxid(params[0]);
|
|
7
|
+
if (txid === null)
|
|
8
|
+
return invalidParams("Invalid tx hash");
|
|
9
|
+
const verbose = validateOptionalBool(params[1]);
|
|
10
|
+
if (verbose === null)
|
|
11
|
+
return invalidParams("Invalid verbose parameter");
|
|
12
|
+
const rawHex = ctx.node.getRawTx(txid);
|
|
13
|
+
if (rawHex === undefined) {
|
|
14
|
+
return err(ERR_BAD_REQUEST, "No such mempool or blockchain transaction. Use gettransaction for wallet transactions.");
|
|
15
|
+
}
|
|
16
|
+
if (!verbose)
|
|
17
|
+
return ok(rawHex);
|
|
18
|
+
// Verbose mode: decode and build full response
|
|
19
|
+
const decoded = decodeTransactionBch(hexToBin(rawHex));
|
|
20
|
+
if (typeof decoded === "string") {
|
|
21
|
+
return err(ERR_INTERNAL, "Failed to decode transaction");
|
|
22
|
+
}
|
|
23
|
+
const record = ctx.node.getTx(txid);
|
|
24
|
+
const tip = ctx.node.getTip();
|
|
25
|
+
const txHeight = record?.height ?? 0;
|
|
26
|
+
const confirmations = txHeight > 0 && tip ? tip.height - txHeight + 1 : 0;
|
|
27
|
+
const blockHeader = txHeight > 0 ? ctx.node.getHeader(txHeight) : undefined;
|
|
28
|
+
const vin = decoded.inputs.map((input) => ({
|
|
29
|
+
txid: binToHex(input.outpointTransactionHash),
|
|
30
|
+
vout: input.outpointIndex,
|
|
31
|
+
scriptSig: {
|
|
32
|
+
asm: "",
|
|
33
|
+
hex: binToHex(input.unlockingBytecode),
|
|
34
|
+
},
|
|
35
|
+
sequence: input.sequenceNumber,
|
|
36
|
+
}));
|
|
37
|
+
const vout = decoded.outputs.map((output, n) => {
|
|
38
|
+
const scriptHex = binToHex(output.lockingBytecode);
|
|
39
|
+
const bc = output.lockingBytecode;
|
|
40
|
+
let type = "nonstandard";
|
|
41
|
+
let asm = "";
|
|
42
|
+
const addresses = [];
|
|
43
|
+
if (bc.length === 0) {
|
|
44
|
+
type = "nulldata";
|
|
45
|
+
}
|
|
46
|
+
else if (bc[0] === 0x6a) {
|
|
47
|
+
type = "nulldata";
|
|
48
|
+
asm = `OP_RETURN${bc.length > 1 ? ` ${binToHex(bc.slice(1))}` : ""}`;
|
|
49
|
+
}
|
|
50
|
+
else if (bc.length === 25 &&
|
|
51
|
+
bc[0] === 0x76 &&
|
|
52
|
+
bc[1] === 0xa9 &&
|
|
53
|
+
bc[2] === 0x14 &&
|
|
54
|
+
bc[23] === 0x88 &&
|
|
55
|
+
bc[24] === 0xac) {
|
|
56
|
+
type = "pubkeyhash";
|
|
57
|
+
const addrOpts = ctx.addressPrefix
|
|
58
|
+
? { bytecode: bc, prefix: ctx.addressPrefix }
|
|
59
|
+
: { bytecode: bc };
|
|
60
|
+
const result = lockingBytecodeToCashAddress(addrOpts);
|
|
61
|
+
if (typeof result !== "string")
|
|
62
|
+
addresses.push(result.address);
|
|
63
|
+
}
|
|
64
|
+
else if (bc.length === 23 && bc[0] === 0xa9 && bc[1] === 0x14 && bc[22] === 0x87) {
|
|
65
|
+
type = "scripthash";
|
|
66
|
+
const addrOpts = ctx.addressPrefix
|
|
67
|
+
? { bytecode: bc, prefix: ctx.addressPrefix }
|
|
68
|
+
: { bytecode: bc };
|
|
69
|
+
const result = lockingBytecodeToCashAddress(addrOpts);
|
|
70
|
+
if (typeof result !== "string")
|
|
71
|
+
addresses.push(result.address);
|
|
72
|
+
}
|
|
73
|
+
const item = {
|
|
74
|
+
n,
|
|
75
|
+
value: Number(output.valueSatoshis) / 1e8,
|
|
76
|
+
scriptPubKey: {
|
|
77
|
+
asm,
|
|
78
|
+
hex: scriptHex,
|
|
79
|
+
reqSigs: type === "nulldata" ? 0 : 1,
|
|
80
|
+
type,
|
|
81
|
+
addresses,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
if (output.token) {
|
|
85
|
+
const td = {
|
|
86
|
+
category: binToHex(output.token.category),
|
|
87
|
+
amount: String(output.token.amount),
|
|
88
|
+
};
|
|
89
|
+
if (output.token.nft) {
|
|
90
|
+
td.nft = {
|
|
91
|
+
capability: output.token.nft.capability,
|
|
92
|
+
commitment: binToHex(output.token.nft.commitment),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
item.tokenData = td;
|
|
96
|
+
}
|
|
97
|
+
return item;
|
|
98
|
+
});
|
|
99
|
+
return ok({
|
|
100
|
+
txid,
|
|
101
|
+
hash: txid,
|
|
102
|
+
hex: rawHex,
|
|
103
|
+
size: hexToBin(rawHex).length,
|
|
104
|
+
version: decoded.version,
|
|
105
|
+
locktime: decoded.locktime,
|
|
106
|
+
vin,
|
|
107
|
+
vout,
|
|
108
|
+
blockhash: blockHeader?.hash ?? "",
|
|
109
|
+
blocktime: blockHeader?.timestamp ?? 0,
|
|
110
|
+
time: blockHeader?.timestamp ?? 0,
|
|
111
|
+
confirmations,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/** blockchain.transaction.get_merkle */
|
|
115
|
+
export function getMerkle(ctx, params) {
|
|
116
|
+
const txid = validateTxid(params[0]);
|
|
117
|
+
if (txid === null)
|
|
118
|
+
return invalidParams("Invalid tx hash");
|
|
119
|
+
// Height can be provided explicitly or looked up from the tx record
|
|
120
|
+
let height;
|
|
121
|
+
if (params[1] !== undefined && params[1] !== null) {
|
|
122
|
+
const h = validateNonNegativeInt(params[1]);
|
|
123
|
+
if (h === null)
|
|
124
|
+
return invalidParams("Invalid height");
|
|
125
|
+
height = h;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
const txRecord = ctx.node.getTx(txid);
|
|
129
|
+
if (!txRecord) {
|
|
130
|
+
return err(ERR_BAD_REQUEST, "No such mempool or blockchain transaction. Use gettransaction for wallet transactions.");
|
|
131
|
+
}
|
|
132
|
+
if (txRecord.height <= 0) {
|
|
133
|
+
return err(ERR_BAD_REQUEST, "Transaction is not confirmed");
|
|
134
|
+
}
|
|
135
|
+
height = txRecord.height;
|
|
136
|
+
}
|
|
137
|
+
const txids = ctx.node.getTxidsAtHeight(height);
|
|
138
|
+
if (!txids) {
|
|
139
|
+
return err(ERR_BAD_REQUEST, "Block not found at the requested height");
|
|
140
|
+
}
|
|
141
|
+
const result = computeTxMerkleBranch(txids, txid);
|
|
142
|
+
if (!result) {
|
|
143
|
+
return err(ERR_BAD_REQUEST, "Transaction not found in the specified block");
|
|
144
|
+
}
|
|
145
|
+
return ok({
|
|
146
|
+
block_height: height,
|
|
147
|
+
pos: result.pos,
|
|
148
|
+
merkle: result.merkle,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/** blockchain.transaction.id_from_pos */
|
|
152
|
+
export function idFromPos(ctx, params) {
|
|
153
|
+
const height = validateNonNegativeInt(params[0]);
|
|
154
|
+
if (height === null)
|
|
155
|
+
return invalidParams("Invalid height");
|
|
156
|
+
const txPos = validateNonNegativeInt(params[1]);
|
|
157
|
+
if (txPos === null)
|
|
158
|
+
return invalidParams("Invalid tx_pos");
|
|
159
|
+
const merkle = validateOptionalBool(params[2]);
|
|
160
|
+
if (merkle === null)
|
|
161
|
+
return invalidParams("Invalid merkle parameter");
|
|
162
|
+
const txids = ctx.node.getTxidsAtHeight(height);
|
|
163
|
+
if (!txids) {
|
|
164
|
+
return err(ERR_BAD_REQUEST, "Block not found at the requested height");
|
|
165
|
+
}
|
|
166
|
+
if (txPos >= txids.length) {
|
|
167
|
+
return err(ERR_BAD_REQUEST, "tx_pos out of range");
|
|
168
|
+
}
|
|
169
|
+
const txid = txids[txPos];
|
|
170
|
+
if (txid === undefined) {
|
|
171
|
+
return err(ERR_BAD_REQUEST, "tx_pos out of range");
|
|
172
|
+
}
|
|
173
|
+
if (!merkle) {
|
|
174
|
+
return ok(txid);
|
|
175
|
+
}
|
|
176
|
+
const branch = computeTxMerkleBranch(txids, txid);
|
|
177
|
+
if (!branch) {
|
|
178
|
+
return err(ERR_BAD_REQUEST, "Failed to compute merkle branch");
|
|
179
|
+
}
|
|
180
|
+
return ok({
|
|
181
|
+
tx_hash: txid,
|
|
182
|
+
merkle: branch.merkle,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/** blockchain.transaction.broadcast */
|
|
186
|
+
export function broadcast(ctx, params) {
|
|
187
|
+
const rawTx = params[0];
|
|
188
|
+
if (typeof rawTx !== "string" || rawTx.length === 0 || !isHex(rawTx)) {
|
|
189
|
+
return invalidParams("Invalid raw transaction hex");
|
|
190
|
+
}
|
|
191
|
+
const result = ctx.node.submitTransaction(rawTx);
|
|
192
|
+
if (!result.success) {
|
|
193
|
+
// Match Fulcrum error format: "the transaction was rejected by network rules.\n\n<reason> (code <code>)\n"
|
|
194
|
+
const msg = `the transaction was rejected by network rules.\n\n${result.error} (code ${result.code})\n`;
|
|
195
|
+
return err(ERR_DAEMON_ERROR, msg);
|
|
196
|
+
}
|
|
197
|
+
return ok(result.txid);
|
|
198
|
+
}
|
|
199
|
+
/** blockchain.transaction.get_height */
|
|
200
|
+
export function getHeight(ctx, params) {
|
|
201
|
+
const txid = validateTxid(params[0]);
|
|
202
|
+
if (txid === null)
|
|
203
|
+
return invalidParams("Invalid tx hash");
|
|
204
|
+
const record = ctx.node.getTx(txid);
|
|
205
|
+
if (!record) {
|
|
206
|
+
// Check mempool
|
|
207
|
+
const memTx = ctx.node.getMempoolTx(txid);
|
|
208
|
+
if (memTx)
|
|
209
|
+
return ok(0);
|
|
210
|
+
return ok(null);
|
|
211
|
+
}
|
|
212
|
+
return ok(record.height > 0 ? record.height : 0);
|
|
213
|
+
}
|
|
214
|
+
/** blockchain.transaction.get_confirmed_blockhash */
|
|
215
|
+
export function getConfirmedBlockhash(ctx, params) {
|
|
216
|
+
const txid = validateTxid(params[0]);
|
|
217
|
+
if (txid === null)
|
|
218
|
+
return invalidParams("Invalid tx hash");
|
|
219
|
+
const includeHeader = validateOptionalBool(params[1]);
|
|
220
|
+
if (includeHeader === null)
|
|
221
|
+
return invalidParams("Invalid include_header parameter");
|
|
222
|
+
const record = ctx.node.getTx(txid);
|
|
223
|
+
if (!record || record.height <= 0) {
|
|
224
|
+
return err(ERR_BAD_REQUEST, "Transaction not confirmed");
|
|
225
|
+
}
|
|
226
|
+
const header = ctx.node.getHeader(record.height);
|
|
227
|
+
if (!header) {
|
|
228
|
+
return err(ERR_BAD_REQUEST, "Block not found at the requested height");
|
|
229
|
+
}
|
|
230
|
+
if (includeHeader) {
|
|
231
|
+
return ok({
|
|
232
|
+
block_hash: header.hash,
|
|
233
|
+
block_height: record.height,
|
|
234
|
+
block_header: header.hex,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
return ok({
|
|
238
|
+
block_hash: header.hash,
|
|
239
|
+
block_height: record.height,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
/** blockchain.transaction.dsproof.get */
|
|
243
|
+
export function dsproofGet(ctx, params) {
|
|
244
|
+
const txid = validateTxid(params[0]);
|
|
245
|
+
if (txid === null)
|
|
246
|
+
return invalidParams("Invalid tx hash");
|
|
247
|
+
return ok(ctx.getDsproof ? ctx.getDsproof(txid) : null);
|
|
248
|
+
}
|
|
249
|
+
/** blockchain.transaction.dsproof.list */
|
|
250
|
+
export function dsproofList(ctx, _params) {
|
|
251
|
+
return ok(ctx.listDsproofs ? ctx.listDsproofs() : []);
|
|
252
|
+
}
|
|
253
|
+
/** Maximum transactions in a single broadcast_package call. */
|
|
254
|
+
const MAX_PACKAGE_SIZE = 1000;
|
|
255
|
+
/** blockchain.transaction.broadcast_package */
|
|
256
|
+
export function broadcastPackage(ctx, params) {
|
|
257
|
+
const rawTxs = params[0];
|
|
258
|
+
if (!Array.isArray(rawTxs) || rawTxs.length === 0) {
|
|
259
|
+
return invalidParams("Expected non-empty array of raw transaction hexes");
|
|
260
|
+
}
|
|
261
|
+
if (rawTxs.length > MAX_PACKAGE_SIZE) {
|
|
262
|
+
return invalidParams(`Package exceeds maximum size of ${MAX_PACKAGE_SIZE}`);
|
|
263
|
+
}
|
|
264
|
+
const txids = [];
|
|
265
|
+
for (const rawTx of rawTxs) {
|
|
266
|
+
if (typeof rawTx !== "string" || rawTx.length === 0 || !isHex(rawTx)) {
|
|
267
|
+
return invalidParams("Invalid raw transaction hex in package");
|
|
268
|
+
}
|
|
269
|
+
const result = ctx.node.submitTransaction(rawTx);
|
|
270
|
+
if (!result.success) {
|
|
271
|
+
const msg = `the transaction was rejected by network rules.\n\n${result.error} (code ${result.code})\n`;
|
|
272
|
+
return err(ERR_DAEMON_ERROR, msg);
|
|
273
|
+
}
|
|
274
|
+
txids.push(result.txid);
|
|
275
|
+
}
|
|
276
|
+
return ok(txids);
|
|
277
|
+
}
|
|
278
|
+
/** blockchain.transaction.subscribe — returns current confirmation status. */
|
|
279
|
+
export function txSubscribe(ctx, params) {
|
|
280
|
+
const txid = validateTxid(params[0]);
|
|
281
|
+
if (txid === null)
|
|
282
|
+
return invalidParams("Invalid tx hash");
|
|
283
|
+
const record = ctx.node.getTx(txid);
|
|
284
|
+
const memTx = ctx.node.getMempoolTx(txid);
|
|
285
|
+
const tip = ctx.node.getTip();
|
|
286
|
+
let confirmations = null;
|
|
287
|
+
if (record && record.height > 0 && tip) {
|
|
288
|
+
confirmations = tip.height - record.height + 1;
|
|
289
|
+
}
|
|
290
|
+
else if (record || memTx) {
|
|
291
|
+
confirmations = 0;
|
|
292
|
+
}
|
|
293
|
+
return ok([txid, confirmations]);
|
|
294
|
+
}
|
|
295
|
+
/** blockchain.transaction.unsubscribe */
|
|
296
|
+
export function txUnsubscribe(_ctx, params) {
|
|
297
|
+
const txid = validateTxid(params[0]);
|
|
298
|
+
if (txid === null)
|
|
299
|
+
return invalidParams("Invalid tx hash");
|
|
300
|
+
return ok(true);
|
|
301
|
+
}
|
|
302
|
+
/** blockchain.transaction.dsproof.subscribe — returns current dsproof status. */
|
|
303
|
+
export function dsproofSubscribe(ctx, params) {
|
|
304
|
+
const txid = validateTxid(params[0]);
|
|
305
|
+
if (txid === null)
|
|
306
|
+
return invalidParams("Invalid tx hash");
|
|
307
|
+
// Initial status: look up from context hook, default to no dsproof
|
|
308
|
+
const dsproof = ctx.getDsproof ? ctx.getDsproof(txid) : null;
|
|
309
|
+
return ok([txid, dsproof]);
|
|
310
|
+
}
|
|
311
|
+
/** blockchain.transaction.dsproof.unsubscribe */
|
|
312
|
+
export function dsproofUnsubscribe(_ctx, params) {
|
|
313
|
+
const txid = validateTxid(params[0]);
|
|
314
|
+
if (txid === null)
|
|
315
|
+
return invalidParams("Invalid tx hash");
|
|
316
|
+
return ok(true);
|
|
317
|
+
}
|
|
318
|
+
//# sourceMappingURL=transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,QAAQ,EACR,oBAAoB,EACpB,QAAQ,EACR,KAAK,EACL,4BAA4B,GAC5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EACN,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,GAAG,EAEH,aAAa,EACb,EAAE,EAEF,sBAAsB,EACtB,oBAAoB,EACpB,YAAY,GACZ,MAAM,YAAY,CAAC;AAEpB,iCAAiC;AACjC,MAAM,UAAU,GAAG,CAAC,GAAoB,EAAE,MAAiB;IAC1D,MAAM,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAE3D,MAAM,OAAO,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,aAAa,CAAC,2BAA2B,CAAC,CAAC;IAExE,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,GAAG,CACT,eAAe,EACf,wFAAwF,CACxF,CAAC;IACH,CAAC;IAED,IAAI,CA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ACvE,MAAM,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAC3D,mEAAmE;IACnE,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7D,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;AAC5B,CAAC;AAED,iDAAiD;AACjD,MAAM,UAAU,kBAAkB,CAAC,IAAqB,EAAE,MAAiB;IAC1E,MAAM,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAC3D,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Indexer } from "./indexer.js";
|
|
2
|
+
import type { Schema } from "./schema.js";
|
|
3
|
+
/**
|
|
4
|
+
* Minimal Transport-compatible interface.
|
|
5
|
+
*
|
|
6
|
+
* This mirrors the rpckit Transport shape so that a Indexer instance
|
|
7
|
+
* can be used as a drop-in replacement for a WebSocket/TCP transport
|
|
8
|
+
* in consumers like ElectrumNetworkProvider.
|
|
9
|
+
*/
|
|
10
|
+
export interface IndexerTransport<S extends Schema> {
|
|
11
|
+
readonly url: string;
|
|
12
|
+
connect(): Promise<void>;
|
|
13
|
+
close(): Promise<void>;
|
|
14
|
+
request: Indexer<S>["request"];
|
|
15
|
+
subscribe: Indexer<S>["subscribe"];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Wrap a Indexer instance as a Transport-compatible object.
|
|
19
|
+
*
|
|
20
|
+
* The returned object has the same `request` / `subscribe` methods
|
|
21
|
+
* plus no-op `connect()` / `close()` and a synthetic `url`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function asTransport<S extends Schema>(mc: Indexer<S>): IndexerTransport<S>;
|
|
24
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,MAAM;IACjD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAC/B,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;CACnC;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAQjF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wrap a Indexer instance as a Transport-compatible object.
|
|
3
|
+
*
|
|
4
|
+
* The returned object has the same `request` / `subscribe` methods
|
|
5
|
+
* plus no-op `connect()` / `close()` and a synthetic `url`.
|
|
6
|
+
*/
|
|
7
|
+
export function asTransport(mc) {
|
|
8
|
+
return {
|
|
9
|
+
url: "mem-cash://local",
|
|
10
|
+
async connect() { },
|
|
11
|
+
async close() { },
|
|
12
|
+
request: mc.request,
|
|
13
|
+
subscribe: mc.subscribe,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAkBA;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAmB,EAAc;IAC3D,OAAO;QACN,GAAG,EAAE,kBAAkB;QACvB,KAAK,CAAC,OAAO,KAAI,CAAC;QAClB,KAAK,CAAC,KAAK,KAAI,CAAC;QAChB,OAAO,EAAE,EAAE,CAAC,OAAO;QACnB,SAAS,EAAE,EAAE,CAAC,SAAS;KACvB,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Node } from "@mem-cash/core";
|
|
2
|
+
import type { BlockHeader, ScriptHash, Txid } from "@mem-cash/types";
|
|
3
|
+
/** JSON-RPC error object. */
|
|
4
|
+
export interface ProtocolError {
|
|
5
|
+
readonly code: number;
|
|
6
|
+
readonly message: string;
|
|
7
|
+
}
|
|
8
|
+
/** Result of a protocol handler: either a success value or an error. */
|
|
9
|
+
export type HandlerResult = {
|
|
10
|
+
readonly result: unknown;
|
|
11
|
+
} | {
|
|
12
|
+
readonly error: ProtocolError;
|
|
13
|
+
};
|
|
14
|
+
/** A protocol method handler function. */
|
|
15
|
+
export type Handler = (ctx: ProtocolContext, params: unknown[]) => HandlerResult | Promise<HandlerResult>;
|
|
16
|
+
/** Context provided to all protocol handlers. */
|
|
17
|
+
export interface ProtocolContext {
|
|
18
|
+
readonly node: Node;
|
|
19
|
+
readonly serverVersion: string;
|
|
20
|
+
readonly protocolMin: string;
|
|
21
|
+
readonly protocolMax: string;
|
|
22
|
+
readonly genesisHash: string;
|
|
23
|
+
readonly hashFunction: string;
|
|
24
|
+
/** Register a scripthash subscription. */
|
|
25
|
+
readonly subscribeScriptHash?: (scriptHash: ScriptHash) => void;
|
|
26
|
+
/** Unregister a scripthash subscription. Returns true if was subscribed. */
|
|
27
|
+
readonly unsubscribeScriptHash?: (scriptHash: ScriptHash) => boolean;
|
|
28
|
+
/** Register a headers subscription. */
|
|
29
|
+
readonly subscribeHeaders?: () => void;
|
|
30
|
+
/** Unregister a headers subscription. Returns true if was subscribed. */
|
|
31
|
+
readonly unsubscribeHeaders?: () => boolean;
|
|
32
|
+
/** Estimate fee in BCH/kB for target confirmation blocks. Returns -1 if unavailable. */
|
|
33
|
+
readonly estimateFee?: (blocks: number) => Promise<number>;
|
|
34
|
+
/** Get minimum relay fee in BCH/kB. */
|
|
35
|
+
readonly getRelayFee?: () => number;
|
|
36
|
+
/** Look up a stored dsproof for a txid. Returns null if none exists. */
|
|
37
|
+
readonly getDsproof?: (txid: string) => DsproofData | null;
|
|
38
|
+
/** List all txids that have dsproofs. */
|
|
39
|
+
readonly listDsproofs?: () => string[];
|
|
40
|
+
/** Server banner text. */
|
|
41
|
+
readonly banner?: string;
|
|
42
|
+
/** Server donation address. */
|
|
43
|
+
readonly donationAddress?: string;
|
|
44
|
+
/** CashAddress prefix for address encoding (default: "bitcoincash"). */
|
|
45
|
+
readonly addressPrefix?: string;
|
|
46
|
+
}
|
|
47
|
+
/** Double-spend proof data. */
|
|
48
|
+
export interface DsproofData {
|
|
49
|
+
readonly dspid: string;
|
|
50
|
+
readonly txid: string;
|
|
51
|
+
readonly hex: string;
|
|
52
|
+
readonly outpoint: {
|
|
53
|
+
readonly txid: string;
|
|
54
|
+
readonly vout: number;
|
|
55
|
+
};
|
|
56
|
+
readonly descendants: readonly string[];
|
|
57
|
+
}
|
|
58
|
+
export declare const ERR_INVALID_REQUEST = -32600;
|
|
59
|
+
export declare const ERR_METHOD_NOT_FOUND = -32601;
|
|
60
|
+
export declare const ERR_INVALID_PARAMS = -32602;
|
|
61
|
+
export declare const ERR_INTERNAL = -32603;
|
|
62
|
+
export declare const ERR_BAD_REQUEST = 1;
|
|
63
|
+
export declare const ERR_DAEMON_ERROR = 2;
|
|
64
|
+
/** Create a success result. */
|
|
65
|
+
export declare function ok(value: unknown): HandlerResult;
|
|
66
|
+
/** Create an error result. */
|
|
67
|
+
export declare function err(code: number, message: string): HandlerResult;
|
|
68
|
+
/** Create an invalid-params error. */
|
|
69
|
+
export declare function invalidParams(message: string): HandlerResult;
|
|
70
|
+
/** Create an internal error. */
|
|
71
|
+
export declare function internalError(message: string): HandlerResult;
|
|
72
|
+
/** Validate a scripthash parameter (64 hex chars). Returns null on failure. */
|
|
73
|
+
export declare function validateScriptHash(param: unknown): ScriptHash | null;
|
|
74
|
+
/** Validate a txid parameter (64 hex chars). Returns null on failure. */
|
|
75
|
+
export declare function validateTxid(param: unknown): Txid | null;
|
|
76
|
+
/** Validate a non-negative integer parameter. Returns null on failure. */
|
|
77
|
+
export declare function validateNonNegativeInt(param: unknown): number | null;
|
|
78
|
+
/** Validate a boolean parameter (or absent). Returns undefined if not provided, null on bad type. */
|
|
79
|
+
export declare function validateOptionalBool(param: unknown): boolean | undefined | null;
|
|
80
|
+
/** Format a block header for the Electrum protocol response. */
|
|
81
|
+
export declare function formatHeaderResponse(header: BlockHeader): {
|
|
82
|
+
height: number;
|
|
83
|
+
hex: string;
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAErE,6BAA6B;AAC7B,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CACzB;AAED,wEAAwE;AACxE,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,QAAQ,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AAK,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI,CAGxD;AAED,0EAA0E;AAC1E,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAGpE;AAED,qGAAqG;AACrG,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,IAAI,CAI/E;AAED,gEAAgE;AAChE,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,WAAW,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAEzF"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { isHex } from "@bitauth/libauth";
|
|
2
|
+
// --- Standard JSON-RPC error codes ---
|
|
3
|
+
export const ERR_INVALID_REQUEST = -32600;
|
|
4
|
+
export const ERR_METHOD_NOT_FOUND = -32601;
|
|
5
|
+
export const ERR_INVALID_PARAMS = -32602;
|
|
6
|
+
export const ERR_INTERNAL = -32603;
|
|
7
|
+
// --- Application error codes (matching Fulcrum) ---
|
|
8
|
+
export const ERR_BAD_REQUEST = 1;
|
|
9
|
+
export const ERR_DAEMON_ERROR = 2;
|
|
10
|
+
// --- Result helpers ---
|
|
11
|
+
/** Create a success result. */
|
|
12
|
+
export function ok(value) {
|
|
13
|
+
return { result: value };
|
|
14
|
+
}
|
|
15
|
+
/** Create an error result. */
|
|
16
|
+
export function err(code, message) {
|
|
17
|
+
return { error: { code, message } };
|
|
18
|
+
}
|
|
19
|
+
/** Create an invalid-params error. */
|
|
20
|
+
export function invalidParams(message) {
|
|
21
|
+
return err(ERR_INVALID_PARAMS, message);
|
|
22
|
+
}
|
|
23
|
+
/** Create an internal error. */
|
|
24
|
+
export function internalError(message) {
|
|
25
|
+
return err(ERR_INTERNAL, message);
|
|
26
|
+
}
|
|
27
|
+
// --- Validation helpers ---
|
|
28
|
+
/** Validate a scripthash parameter (64 hex chars). Returns null on failure. */
|
|
29
|
+
export function validateScriptHash(param) {
|
|
30
|
+
if (typeof param !== "string" || param.length !== 64 || !isHex(param))
|
|
31
|
+
return null;
|
|
32
|
+
return param;
|
|
33
|
+
}
|
|
34
|
+
/** Validate a txid parameter (64 hex chars). Returns null on failure. */
|
|
35
|
+
export function validateTxid(param) {
|
|
36
|
+
if (typeof param !== "string" || param.length !== 64 || !isHex(param))
|
|
37
|
+
return null;
|
|
38
|
+
return param;
|
|
39
|
+
}
|
|
40
|
+
/** Validate a non-negative integer parameter. Returns null on failure. */
|
|
41
|
+
export function validateNonNegativeInt(param) {
|
|
42
|
+
if (typeof param !== "number" || !Number.isInteger(param) || param < 0)
|
|
43
|
+
return null;
|
|
44
|
+
return param;
|
|
45
|
+
}
|
|
46
|
+
/** Validate a boolean parameter (or absent). Returns undefined if not provided, null on bad type. */
|
|
47
|
+
export function validateOptionalBool(param) {
|
|
48
|
+
if (param === undefined || param === null)
|
|
49
|
+
return undefined;
|
|
50
|
+
if (typeof param !== "boolean")
|
|
51
|
+
return null;
|
|
52
|
+
return param;
|
|
53
|
+
}
|
|
54
|
+
/** Format a block header for the Electrum protocol response. */
|
|
55
|
+
export function formatHeaderResponse(header) {
|
|
56
|
+
return { height: header.height, hex: header.hex };
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAkEzC,wCAAwC;AAExC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAK,CAAC;AAC1C,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAK,CAAC;AAC3C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAK,CAAC;AACzC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAK,CAAC;AAEnC,qDAAqD;AAErD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