opnet 1.2.25 → 1.2.26
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/browser/_version.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/providers/AbstractRpcProvider.d.ts +2 -0
- package/browser/providers/interfaces/JSONRpcMethods.d.ts +4 -4
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/contracts/CallResult.js +3 -1
- package/build/providers/AbstractRpcProvider.d.ts +2 -0
- package/build/providers/AbstractRpcProvider.js +20 -0
- package/build/providers/interfaces/JSONRpcMethods.d.ts +4 -4
- package/build/providers/interfaces/JSONRpcMethods.js +3 -3
- package/package.json +108 -108
- package/src/_version.ts +1 -1
- package/src/contracts/CallResult.ts +3 -1
- package/src/providers/AbstractRpcProvider.ts +40 -0
- package/src/providers/interfaces/JSONRpcMethods.ts +7 -10
|
@@ -27,12 +27,14 @@ export declare abstract class AbstractRpcProvider {
|
|
|
27
27
|
private chainId;
|
|
28
28
|
private gasCache;
|
|
29
29
|
private lastFetchedGas;
|
|
30
|
+
private preimageCache;
|
|
30
31
|
protected constructor(network: Network);
|
|
31
32
|
private _utxoManager;
|
|
32
33
|
get utxoManager(): UTXOsManager;
|
|
33
34
|
getPublicKeyInfo(address: string): Promise<Address>;
|
|
34
35
|
validateAddress(addr: string | Address, network: Network): AddressTypes | null;
|
|
35
36
|
getBlockNumber(): Promise<bigint>;
|
|
37
|
+
getPreimage(): Promise<Buffer>;
|
|
36
38
|
getBlock(blockNumberOrHash: BlockTag, prefetchTxs?: boolean): Promise<Block>;
|
|
37
39
|
getBlocks(blockNumbers: BlockTag[], prefetchTxs?: boolean): Promise<Block[]>;
|
|
38
40
|
getBlockByHash(blockHash: string): Promise<Block>;
|
|
@@ -7,14 +7,14 @@ export declare enum JSONRpcMethods {
|
|
|
7
7
|
GAS = "btc_gas",
|
|
8
8
|
GET_TRANSACTION_BY_HASH = "btc_getTransactionByHash",
|
|
9
9
|
BROADCAST_TRANSACTION = "btc_sendRawTransaction",
|
|
10
|
-
|
|
10
|
+
TRANSACTION_PREIMAGE = "btc_preimage",
|
|
11
|
+
PUBLIC_KEY_INFO = "btc_publicKeyInfo",
|
|
11
12
|
GET_UTXOS = "btc_getUTXOs",
|
|
13
|
+
GET_BALANCE = "btc_getBalance",
|
|
12
14
|
BLOCK_WITNESS = "btc_blockWitness",
|
|
13
15
|
GET_TRANSACTION_RECEIPT = "btc_getTransactionReceipt",
|
|
14
16
|
GET_CODE = "btc_getCode",
|
|
15
17
|
GET_STORAGE_AT = "btc_getStorageAt",
|
|
16
|
-
GET_BALANCE = "btc_getBalance",
|
|
17
18
|
CALL = "btc_call",
|
|
18
|
-
SIMULATE = "btc_simulate"
|
|
19
|
-
PUBLIC_KEY_INFO = "btc_publicKeyInfo"
|
|
19
|
+
SIMULATE = "btc_simulate"
|
|
20
20
|
}
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.2.
|
|
1
|
+
export declare const version = "1.2.26";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.2.
|
|
1
|
+
export const version = '1.2.26';
|
|
@@ -51,17 +51,19 @@ export class CallResult {
|
|
|
51
51
|
if (!UTXOs || UTXOs.length === 0) {
|
|
52
52
|
throw new Error('No UTXOs found');
|
|
53
53
|
}
|
|
54
|
+
const preimage = await this.#provider.getPreimage();
|
|
54
55
|
const params = {
|
|
55
56
|
calldata: this.calldata,
|
|
56
57
|
priorityFee: priorityFee,
|
|
57
58
|
gasSatFee: this.estimatedSatGas,
|
|
58
59
|
feeRate: interactionParams.feeRate || 10,
|
|
59
60
|
from: interactionParams.refundTo,
|
|
60
|
-
signer: interactionParams.signer,
|
|
61
61
|
utxos: UTXOs,
|
|
62
62
|
to: this.to,
|
|
63
63
|
network: interactionParams.network,
|
|
64
64
|
optionalOutputs: interactionParams.extraOutputs || [],
|
|
65
|
+
signer: interactionParams.signer,
|
|
66
|
+
preimage: preimage,
|
|
65
67
|
};
|
|
66
68
|
const transaction = await factory.signInteraction(params);
|
|
67
69
|
const tx1 = await this.#provider.sendRawTransaction(transaction.fundingTransaction, false);
|
|
@@ -27,12 +27,14 @@ export declare abstract class AbstractRpcProvider {
|
|
|
27
27
|
private chainId;
|
|
28
28
|
private gasCache;
|
|
29
29
|
private lastFetchedGas;
|
|
30
|
+
private preimageCache;
|
|
30
31
|
protected constructor(network: Network);
|
|
31
32
|
private _utxoManager;
|
|
32
33
|
get utxoManager(): UTXOsManager;
|
|
33
34
|
getPublicKeyInfo(address: string): Promise<Address>;
|
|
34
35
|
validateAddress(addr: string | Address, network: Network): AddressTypes | null;
|
|
35
36
|
getBlockNumber(): Promise<bigint>;
|
|
37
|
+
getPreimage(): Promise<Buffer>;
|
|
36
38
|
getBlock(blockNumberOrHash: BlockTag, prefetchTxs?: boolean): Promise<Block>;
|
|
37
39
|
getBlocks(blockNumbers: BlockTag[], prefetchTxs?: boolean): Promise<Block[]>;
|
|
38
40
|
getBlockByHash(blockHash: string): Promise<Block>;
|
|
@@ -15,6 +15,7 @@ export class AbstractRpcProvider {
|
|
|
15
15
|
chainId;
|
|
16
16
|
gasCache;
|
|
17
17
|
lastFetchedGas = 0;
|
|
18
|
+
preimageCache;
|
|
18
19
|
constructor(network) {
|
|
19
20
|
this.network = network;
|
|
20
21
|
}
|
|
@@ -53,6 +54,25 @@ export class AbstractRpcProvider {
|
|
|
53
54
|
const result = rawBlockNumber.result;
|
|
54
55
|
return BigInt(result);
|
|
55
56
|
}
|
|
57
|
+
async getPreimage() {
|
|
58
|
+
if (this.preimageCache) {
|
|
59
|
+
if (this.preimageCache.expireAt > Date.now()) {
|
|
60
|
+
return this.preimageCache.preimage;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const payload = this.buildJsonRpcPayload(JSONRpcMethods.TRANSACTION_PREIMAGE, []);
|
|
64
|
+
const rawBlockNumber = await this.callPayloadSingle(payload);
|
|
65
|
+
const result = rawBlockNumber.result;
|
|
66
|
+
if (!result || result.preimage === '0000000000000000000000000000000000000000000000000000000000000000') {
|
|
67
|
+
throw new Error('No preimage found. OPNet is probably not active yet on this blockchain.');
|
|
68
|
+
}
|
|
69
|
+
const preimage = Buffer.from(result.preimage, 'hex');
|
|
70
|
+
this.preimageCache = {
|
|
71
|
+
preimage: preimage,
|
|
72
|
+
expireAt: Date.now() + 10_000
|
|
73
|
+
};
|
|
74
|
+
return preimage;
|
|
75
|
+
}
|
|
56
76
|
async getBlock(blockNumberOrHash, prefetchTxs = false) {
|
|
57
77
|
const method = typeof blockNumberOrHash === 'string'
|
|
58
78
|
? JSONRpcMethods.GET_BLOCK_BY_HASH
|
|
@@ -7,14 +7,14 @@ export declare enum JSONRpcMethods {
|
|
|
7
7
|
GAS = "btc_gas",
|
|
8
8
|
GET_TRANSACTION_BY_HASH = "btc_getTransactionByHash",
|
|
9
9
|
BROADCAST_TRANSACTION = "btc_sendRawTransaction",
|
|
10
|
-
|
|
10
|
+
TRANSACTION_PREIMAGE = "btc_preimage",
|
|
11
|
+
PUBLIC_KEY_INFO = "btc_publicKeyInfo",
|
|
11
12
|
GET_UTXOS = "btc_getUTXOs",
|
|
13
|
+
GET_BALANCE = "btc_getBalance",
|
|
12
14
|
BLOCK_WITNESS = "btc_blockWitness",
|
|
13
15
|
GET_TRANSACTION_RECEIPT = "btc_getTransactionReceipt",
|
|
14
16
|
GET_CODE = "btc_getCode",
|
|
15
17
|
GET_STORAGE_AT = "btc_getStorageAt",
|
|
16
|
-
GET_BALANCE = "btc_getBalance",
|
|
17
18
|
CALL = "btc_call",
|
|
18
|
-
SIMULATE = "btc_simulate"
|
|
19
|
-
PUBLIC_KEY_INFO = "btc_publicKeyInfo"
|
|
19
|
+
SIMULATE = "btc_simulate"
|
|
20
20
|
}
|
|
@@ -8,14 +8,14 @@ export var JSONRpcMethods;
|
|
|
8
8
|
JSONRpcMethods["GAS"] = "btc_gas";
|
|
9
9
|
JSONRpcMethods["GET_TRANSACTION_BY_HASH"] = "btc_getTransactionByHash";
|
|
10
10
|
JSONRpcMethods["BROADCAST_TRANSACTION"] = "btc_sendRawTransaction";
|
|
11
|
-
JSONRpcMethods["
|
|
11
|
+
JSONRpcMethods["TRANSACTION_PREIMAGE"] = "btc_preimage";
|
|
12
|
+
JSONRpcMethods["PUBLIC_KEY_INFO"] = "btc_publicKeyInfo";
|
|
12
13
|
JSONRpcMethods["GET_UTXOS"] = "btc_getUTXOs";
|
|
14
|
+
JSONRpcMethods["GET_BALANCE"] = "btc_getBalance";
|
|
13
15
|
JSONRpcMethods["BLOCK_WITNESS"] = "btc_blockWitness";
|
|
14
16
|
JSONRpcMethods["GET_TRANSACTION_RECEIPT"] = "btc_getTransactionReceipt";
|
|
15
17
|
JSONRpcMethods["GET_CODE"] = "btc_getCode";
|
|
16
18
|
JSONRpcMethods["GET_STORAGE_AT"] = "btc_getStorageAt";
|
|
17
|
-
JSONRpcMethods["GET_BALANCE"] = "btc_getBalance";
|
|
18
19
|
JSONRpcMethods["CALL"] = "btc_call";
|
|
19
20
|
JSONRpcMethods["SIMULATE"] = "btc_simulate";
|
|
20
|
-
JSONRpcMethods["PUBLIC_KEY_INFO"] = "btc_publicKeyInfo";
|
|
21
21
|
})(JSONRpcMethods || (JSONRpcMethods = {}));
|
package/package.json
CHANGED
|
@@ -1,112 +1,112 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
"name": "opnet",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.2.26",
|
|
5
|
+
"author": "OP_NET",
|
|
6
|
+
"description": "The perfect library for building Bitcoin-based applications.",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=21.0.0"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"browser": "./browser/index.js",
|
|
13
|
+
"import": "./build/index.js",
|
|
14
|
+
"require": "./build/index.js",
|
|
15
|
+
"types": "./build/index.d.ts"
|
|
9
16
|
},
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"require": "./build/index.js",
|
|
15
|
-
"types": "./build/index.d.ts"
|
|
16
|
-
},
|
|
17
|
-
"./browser": {
|
|
18
|
-
"import": "./browser/index.js",
|
|
19
|
-
"require": "./browser/index.js",
|
|
20
|
-
"types": "./browser/index.d.ts"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"browser": {
|
|
24
|
-
"./build/index.d.ts": "./browser/index.d.ts",
|
|
25
|
-
"./build/index.js": "./browser/index.js",
|
|
26
|
-
"Buffer": "buffer",
|
|
27
|
-
"crypto": "./src/crypto/crypto-browser.js",
|
|
28
|
-
"stream": "stream-browserify"
|
|
29
|
-
},
|
|
30
|
-
"homepage": "https://opnet.org",
|
|
31
|
-
"keywords": [
|
|
32
|
-
"opnet",
|
|
33
|
-
"bsi",
|
|
34
|
-
"bsi-bitcoin-rpc",
|
|
35
|
-
"bitcoin",
|
|
36
|
-
"btc",
|
|
37
|
-
"bitcoin smart contracts",
|
|
38
|
-
"smart inscriptions",
|
|
39
|
-
"ordinals"
|
|
40
|
-
],
|
|
41
|
-
"license": "MIT",
|
|
42
|
-
"main": "build/index.js",
|
|
43
|
-
"types": "build/index.d.ts",
|
|
44
|
-
"typings": "build/index.d.ts",
|
|
45
|
-
"module": "build/index.js",
|
|
46
|
-
"publishConfig": {
|
|
47
|
-
"access": "public",
|
|
48
|
-
"tag": "latest"
|
|
49
|
-
},
|
|
50
|
-
"repository": {
|
|
51
|
-
"type": "git",
|
|
52
|
-
"url": "git://github.com/btc-vision/opnet.git"
|
|
53
|
-
},
|
|
54
|
-
"scripts": {
|
|
55
|
-
"watch": "gulp watch",
|
|
56
|
-
"build": "gulp build",
|
|
57
|
-
"test": "jest --runInBand",
|
|
58
|
-
"setup": "npm i && npm run build",
|
|
59
|
-
"browserBuild": "webpack --mode production",
|
|
60
|
-
"docs": "typedoc --out docs --tsconfig tsconfig.json --readme README.md --name OPNet --plugin typedoc-material-theme --themeColor '#cb9820' --exclude src/scripts/test.ts --exclude src/index.ts src"
|
|
61
|
-
},
|
|
62
|
-
"devDependencies": {
|
|
63
|
-
"@babel/core": "^7.26.8",
|
|
64
|
-
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
65
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
66
|
-
"@babel/plugin-transform-runtime": "^7.26.8",
|
|
67
|
-
"@babel/preset-env": "^7.26.8",
|
|
68
|
-
"@babel/preset-flow": "^7.25.9",
|
|
69
|
-
"@babel/preset-react": "^7.26.3",
|
|
70
|
-
"@babel/preset-typescript": "^7.26.0",
|
|
71
|
-
"@eslint/js": "^9.20.0",
|
|
72
|
-
"@types/node": "^22.13.2",
|
|
73
|
-
"@types/sha.js": "^2.4.4",
|
|
74
|
-
"@types/ws": "^8.5.14",
|
|
75
|
-
"assert": "^2.1.0",
|
|
76
|
-
"babel-loader": "^9.2.1",
|
|
77
|
-
"babel-plugin-transform-import-meta": "^2.3.2",
|
|
78
|
-
"babel-preset-react": "^6.24.1",
|
|
79
|
-
"babelify": "^10.0.0",
|
|
80
|
-
"eslint": "^9.20.1",
|
|
81
|
-
"gulp": "^5.0.0",
|
|
82
|
-
"gulp-cached": "^1.1.1",
|
|
83
|
-
"gulp-clean": "^0.4.0",
|
|
84
|
-
"gulp-eslint-new": "^2.4.0",
|
|
85
|
-
"gulp-logger-new": "^1.0.1",
|
|
86
|
-
"gulp-typescript": "^6.0.0-alpha.1",
|
|
87
|
-
"https-browserify": "^1.0.0",
|
|
88
|
-
"os-browserify": "^0.3.0",
|
|
89
|
-
"prettier": "^3.5.0",
|
|
90
|
-
"process": "^0.11.10",
|
|
91
|
-
"stream-browserify": "^3.0.0",
|
|
92
|
-
"stream-http": "^3.2.0",
|
|
93
|
-
"ts-loader": "^9.5.2",
|
|
94
|
-
"ts-node": "^10.9.2",
|
|
95
|
-
"typedoc": "^0.27.7",
|
|
96
|
-
"typescript": "^5.7.3",
|
|
97
|
-
"typescript-eslint": "^8.24.0",
|
|
98
|
-
"webpack": "^5.97.1",
|
|
99
|
-
"webpack-cli": "^6.0.1"
|
|
100
|
-
},
|
|
101
|
-
"dependencies": {
|
|
102
|
-
"@bitcoinerlab/secp256k1": "^1.2.0",
|
|
103
|
-
"@btc-vision/bitcoin": "^6.3.6",
|
|
104
|
-
"@btc-vision/bitcoin-rpc": "^1.0.1",
|
|
105
|
-
"@btc-vision/transaction": "^1.2.13",
|
|
106
|
-
"@noble/hashes": "^1.7.1",
|
|
107
|
-
"bignumber.js": "^9.1.2",
|
|
108
|
-
"buffer": "^6.0.3",
|
|
109
|
-
"ecpair": "^2.1.0",
|
|
110
|
-
"tiny-secp256k1": "^2.2.3"
|
|
17
|
+
"./browser": {
|
|
18
|
+
"import": "./browser/index.js",
|
|
19
|
+
"require": "./browser/index.js",
|
|
20
|
+
"types": "./browser/index.d.ts"
|
|
111
21
|
}
|
|
22
|
+
},
|
|
23
|
+
"browser": {
|
|
24
|
+
"./build/index.d.ts": "./browser/index.d.ts",
|
|
25
|
+
"./build/index.js": "./browser/index.js",
|
|
26
|
+
"Buffer": "buffer",
|
|
27
|
+
"crypto": "./src/crypto/crypto-browser.js",
|
|
28
|
+
"stream": "stream-browserify"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://opnet.org",
|
|
31
|
+
"keywords": [
|
|
32
|
+
"opnet",
|
|
33
|
+
"bsi",
|
|
34
|
+
"bsi-bitcoin-rpc",
|
|
35
|
+
"bitcoin",
|
|
36
|
+
"btc",
|
|
37
|
+
"bitcoin smart contracts",
|
|
38
|
+
"smart inscriptions",
|
|
39
|
+
"ordinals"
|
|
40
|
+
],
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"main": "build/index.js",
|
|
43
|
+
"types": "build/index.d.ts",
|
|
44
|
+
"typings": "build/index.d.ts",
|
|
45
|
+
"module": "build/index.js",
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public",
|
|
48
|
+
"tag": "latest"
|
|
49
|
+
},
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "git://github.com/btc-vision/opnet.git"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"watch": "gulp watch",
|
|
56
|
+
"build": "gulp build",
|
|
57
|
+
"test": "jest --runInBand",
|
|
58
|
+
"setup": "npm i && npm run build",
|
|
59
|
+
"browserBuild": "webpack --mode production",
|
|
60
|
+
"docs": "typedoc --out docs --tsconfig tsconfig.json --readme README.md --name OPNet --plugin typedoc-material-theme --themeColor '#cb9820' --exclude src/scripts/test.ts --exclude src/index.ts src"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@babel/core": "^7.26.8",
|
|
64
|
+
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
65
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
66
|
+
"@babel/plugin-transform-runtime": "^7.26.8",
|
|
67
|
+
"@babel/preset-env": "^7.26.8",
|
|
68
|
+
"@babel/preset-flow": "^7.25.9",
|
|
69
|
+
"@babel/preset-react": "^7.26.3",
|
|
70
|
+
"@babel/preset-typescript": "^7.26.0",
|
|
71
|
+
"@eslint/js": "^9.20.0",
|
|
72
|
+
"@types/node": "^22.13.2",
|
|
73
|
+
"@types/sha.js": "^2.4.4",
|
|
74
|
+
"@types/ws": "^8.5.14",
|
|
75
|
+
"assert": "^2.1.0",
|
|
76
|
+
"babel-loader": "^9.2.1",
|
|
77
|
+
"babel-plugin-transform-import-meta": "^2.3.2",
|
|
78
|
+
"babel-preset-react": "^6.24.1",
|
|
79
|
+
"babelify": "^10.0.0",
|
|
80
|
+
"eslint": "^9.20.1",
|
|
81
|
+
"gulp": "^5.0.0",
|
|
82
|
+
"gulp-cached": "^1.1.1",
|
|
83
|
+
"gulp-clean": "^0.4.0",
|
|
84
|
+
"gulp-eslint-new": "^2.4.0",
|
|
85
|
+
"gulp-logger-new": "^1.0.1",
|
|
86
|
+
"gulp-typescript": "^6.0.0-alpha.1",
|
|
87
|
+
"https-browserify": "^1.0.0",
|
|
88
|
+
"os-browserify": "^0.3.0",
|
|
89
|
+
"prettier": "^3.5.0",
|
|
90
|
+
"process": "^0.11.10",
|
|
91
|
+
"stream-browserify": "^3.0.0",
|
|
92
|
+
"stream-http": "^3.2.0",
|
|
93
|
+
"ts-loader": "^9.5.2",
|
|
94
|
+
"ts-node": "^10.9.2",
|
|
95
|
+
"typedoc": "^0.27.7",
|
|
96
|
+
"typescript": "^5.7.3",
|
|
97
|
+
"typescript-eslint": "^8.24.0",
|
|
98
|
+
"webpack": "^5.97.1",
|
|
99
|
+
"webpack-cli": "^6.0.1"
|
|
100
|
+
},
|
|
101
|
+
"dependencies": {
|
|
102
|
+
"@bitcoinerlab/secp256k1": "^1.2.0",
|
|
103
|
+
"@btc-vision/bitcoin": "^6.3.6",
|
|
104
|
+
"@btc-vision/bitcoin-rpc": "^1.0.1",
|
|
105
|
+
"@btc-vision/transaction": "^1.2.14",
|
|
106
|
+
"@noble/hashes": "^1.7.1",
|
|
107
|
+
"bignumber.js": "^9.1.2",
|
|
108
|
+
"buffer": "^6.0.3",
|
|
109
|
+
"ecpair": "^2.1.0",
|
|
110
|
+
"tiny-secp256k1": "^2.2.3"
|
|
111
|
+
}
|
|
112
112
|
}
|
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.2.
|
|
1
|
+
export const version = '1.2.26';
|
|
@@ -127,17 +127,19 @@ export class CallResult<
|
|
|
127
127
|
throw new Error('No UTXOs found');
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
const preimage = await this.#provider.getPreimage();
|
|
130
131
|
const params: IInteractionParameters | InteractionParametersWithoutSigner = {
|
|
131
132
|
calldata: this.calldata,
|
|
132
133
|
priorityFee: priorityFee,
|
|
133
134
|
gasSatFee: this.estimatedSatGas,
|
|
134
135
|
feeRate: interactionParams.feeRate || 10,
|
|
135
136
|
from: interactionParams.refundTo,
|
|
136
|
-
signer: interactionParams.signer,
|
|
137
137
|
utxos: UTXOs,
|
|
138
138
|
to: this.to,
|
|
139
139
|
network: interactionParams.network,
|
|
140
140
|
optionalOutputs: interactionParams.extraOutputs || [],
|
|
141
|
+
signer: interactionParams.signer,
|
|
142
|
+
preimage: preimage,
|
|
141
143
|
};
|
|
142
144
|
|
|
143
145
|
const transaction = await factory.signInteraction(params);
|
|
@@ -36,6 +36,11 @@ import {
|
|
|
36
36
|
import { AddressesInfo, IPublicKeyInfoResult } from './interfaces/PublicKeyInfo.js';
|
|
37
37
|
import { ReorgInformation } from './interfaces/ReorgInformation.js';
|
|
38
38
|
|
|
39
|
+
interface PreimageCache {
|
|
40
|
+
readonly preimage: Buffer;
|
|
41
|
+
readonly expireAt: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
39
44
|
/**
|
|
40
45
|
* @description This class is used to provide an abstract RPC provider.
|
|
41
46
|
* @abstract
|
|
@@ -48,6 +53,8 @@ export abstract class AbstractRpcProvider {
|
|
|
48
53
|
private gasCache: BlockGasParameters | undefined;
|
|
49
54
|
private lastFetchedGas: number = 0;
|
|
50
55
|
|
|
56
|
+
private preimageCache: PreimageCache | undefined;
|
|
57
|
+
|
|
51
58
|
protected constructor(public readonly network: Network) {}
|
|
52
59
|
|
|
53
60
|
private _utxoManager: UTXOsManager = new UTXOsManager(this);
|
|
@@ -119,6 +126,39 @@ export abstract class AbstractRpcProvider {
|
|
|
119
126
|
return BigInt(result);
|
|
120
127
|
}
|
|
121
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Get the latest preimage to use in a transaction.
|
|
131
|
+
* @description This method is used to get the latest preimage to use in a transaction.
|
|
132
|
+
* @returns {Promise<Buffer>} The preimage
|
|
133
|
+
*/
|
|
134
|
+
public async getPreimage(): Promise<Buffer> {
|
|
135
|
+
if(this.preimageCache) {
|
|
136
|
+
if(this.preimageCache.expireAt > Date.now()) {
|
|
137
|
+
return this.preimageCache.preimage;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload(
|
|
142
|
+
JSONRpcMethods.TRANSACTION_PREIMAGE,
|
|
143
|
+
[],
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const rawBlockNumber: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
147
|
+
const result: { preimage: string } = rawBlockNumber.result as {preimage: string};
|
|
148
|
+
|
|
149
|
+
if(!result || result.preimage === '0000000000000000000000000000000000000000000000000000000000000000') {
|
|
150
|
+
throw new Error('No preimage found. OPNet is probably not active yet on this blockchain.');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const preimage = Buffer.from(result.preimage, 'hex');
|
|
154
|
+
this.preimageCache = {
|
|
155
|
+
preimage: preimage,
|
|
156
|
+
expireAt: Date.now() + 10_000
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return preimage;
|
|
160
|
+
}
|
|
161
|
+
|
|
122
162
|
/**
|
|
123
163
|
* Get block by number or hash.
|
|
124
164
|
* @param {BlockTag} blockNumberOrHash The block number or hash
|
|
@@ -14,25 +14,22 @@ export enum JSONRpcMethods {
|
|
|
14
14
|
/** Transactions */
|
|
15
15
|
GET_TRANSACTION_BY_HASH = 'btc_getTransactionByHash',
|
|
16
16
|
BROADCAST_TRANSACTION = 'btc_sendRawTransaction',
|
|
17
|
+
TRANSACTION_PREIMAGE = 'btc_preimage',
|
|
17
18
|
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/** Historical */
|
|
19
|
+
/** Addresses */
|
|
20
|
+
PUBLIC_KEY_INFO = 'btc_publicKeyInfo',
|
|
22
21
|
GET_UTXOS = 'btc_getUTXOs',
|
|
22
|
+
GET_BALANCE = 'btc_getBalance',
|
|
23
23
|
|
|
24
|
-
/**
|
|
24
|
+
/** PoC */
|
|
25
25
|
BLOCK_WITNESS = 'btc_blockWitness',
|
|
26
26
|
|
|
27
27
|
/** State Methods */
|
|
28
28
|
GET_TRANSACTION_RECEIPT = 'btc_getTransactionReceipt',
|
|
29
29
|
GET_CODE = 'btc_getCode',
|
|
30
30
|
GET_STORAGE_AT = 'btc_getStorageAt',
|
|
31
|
-
GET_BALANCE = 'btc_getBalance',
|
|
32
31
|
|
|
32
|
+
/** Simulation */
|
|
33
33
|
CALL = 'btc_call',
|
|
34
34
|
SIMULATE = 'btc_simulate',
|
|
35
|
-
|
|
36
|
-
/** Account */
|
|
37
|
-
PUBLIC_KEY_INFO = 'btc_publicKeyInfo',
|
|
38
|
-
}
|
|
35
|
+
}
|