opnet 1.0.13 → 1.0.15
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/CONTRIBUTING.md +71 -0
- package/README.md +6 -7
- package/browser/_version.d.ts +1 -1
- package/browser/abi/BaseContractProperty.d.ts +3 -0
- package/browser/abi/BitcoinAbiTypes.d.ts +4 -0
- package/browser/abi/BitcoinInterface.d.ts +9 -0
- package/browser/abi/interfaces/BaseContractProperties.d.ts +4 -0
- package/browser/abi/interfaces/BitcoinAbiValue.d.ts +5 -0
- package/browser/abi/interfaces/BitcoinInterfaceAbi.d.ts +11 -0
- package/browser/bitcoin/UTXOs.d.ts +1 -6
- package/browser/bitcoin/interfaces/IUTXO.d.ts +7 -0
- package/browser/common/CommonTypes.d.ts +1 -0
- package/browser/contracts/CallResult.d.ts +6 -3
- package/browser/contracts/Contract.d.ts +28 -0
- package/browser/contracts/interfaces/ICallResult.d.ts +2 -3
- package/browser/contracts/interfaces/IContract.d.ts +4 -0
- package/browser/crypto/crypto-browser.d.ts +7 -0
- package/browser/index.js +1 -1
- package/browser/opnet.d.ts +11 -0
- package/browser/scripts/testContract.d.ts +1 -0
- package/browser/scripts/testMethods.d.ts +1 -0
- package/browser/utils/BitcoinUtils.d.ts +4 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/abi/BaseContractProperty.d.ts +3 -0
- package/build/abi/BaseContractProperty.js +1 -0
- package/build/abi/BitcoinAbiTypes.d.ts +4 -0
- package/build/abi/BitcoinAbiTypes.js +5 -0
- package/build/abi/BitcoinInterface.d.ts +9 -0
- package/build/abi/BitcoinInterface.js +45 -0
- package/build/abi/BitcoinInterfaceAbi.d.ts +3 -0
- package/build/abi/BitcoinInterfaceAbi.js +1 -0
- package/build/abi/enums/ParamTypes.d.ts +0 -0
- package/build/abi/enums/ParamTypes.js +1 -0
- package/build/abi/interface/BitcoinInterface.d.ts +6 -0
- package/build/abi/interface/BitcoinInterface.js +12 -0
- package/build/abi/interface/BitcoinInterfaceAbi.d.ts +3 -0
- package/build/abi/interface/BitcoinInterfaceAbi.js +1 -0
- package/build/abi/interfaces/BaseContractProperties.d.ts +4 -0
- package/build/abi/interfaces/BaseContractProperties.js +1 -0
- package/build/abi/interfaces/BaseContractProperty.d.ts +2 -0
- package/build/abi/interfaces/BaseContractProperty.js +1 -0
- package/build/abi/interfaces/BitcoinAbiInput.d.ts +5 -0
- package/build/abi/interfaces/BitcoinAbiInput.js +1 -0
- package/build/abi/interfaces/BitcoinAbiValue.d.ts +5 -0
- package/build/abi/interfaces/BitcoinAbiValue.js +1 -0
- package/build/abi/interfaces/BitcoinInterfaceAbi.d.ts +11 -0
- package/build/abi/interfaces/BitcoinInterfaceAbi.js +1 -0
- package/build/bitcoin/UTXOs.d.ts +1 -6
- package/build/bitcoin/interfaces/IUTXO.d.ts +7 -0
- package/build/bitcoin/interfaces/IUTXO.js +1 -0
- package/build/common/CommonTypes.d.ts +1 -0
- package/build/contracts/CallResult.d.ts +6 -3
- package/build/contracts/CallResult.js +9 -2
- package/build/contracts/Contract.d.ts +28 -0
- package/build/contracts/Contract.js +206 -0
- package/build/contracts/interfaces/ICallResult.d.ts +2 -3
- package/build/contracts/interfaces/IContract.d.ts +4 -0
- package/build/contracts/interfaces/IContract.js +1 -0
- package/build/interface/BitcoinInterface.d.ts +6 -0
- package/build/interface/BitcoinInterface.js +12 -0
- package/build/interface/BitcoinInterfaceAbi.d.ts +3 -0
- package/build/interface/BitcoinInterfaceAbi.js +1 -0
- package/build/interface/Interface.d.ts +2 -0
- package/build/interface/Interface.js +2 -0
- package/build/interface.d.ts +0 -0
- package/build/interface.js +1 -0
- package/build/opnet.d.ts +11 -0
- package/build/opnet.js +11 -0
- package/build/scripts/test.js +12 -0
- package/build/scripts/testContract.d.ts +1 -0
- package/build/scripts/testContract.js +28 -0
- package/build/scripts/testMethods.d.ts +1 -0
- package/build/scripts/testMethods.js +24 -0
- package/build/utils/BitcoinUtils.d.ts +4 -0
- package/build/utils/BitcoinUtils.js +7 -0
- package/cjs/_version.d.ts +1 -0
- package/cjs/_version.js +4 -0
- package/cjs/abi/BaseContractProperty.d.ts +3 -0
- package/cjs/abi/BaseContractProperty.js +2 -0
- package/cjs/abi/BitcoinAbiTypes.d.ts +4 -0
- package/cjs/abi/BitcoinAbiTypes.js +8 -0
- package/cjs/abi/BitcoinInterface.d.ts +9 -0
- package/cjs/abi/BitcoinInterface.js +49 -0
- package/cjs/abi/interfaces/BaseContractProperties.d.ts +4 -0
- package/cjs/abi/interfaces/BaseContractProperties.js +2 -0
- package/cjs/abi/interfaces/BitcoinAbiValue.d.ts +5 -0
- package/cjs/abi/interfaces/BitcoinAbiValue.js +2 -0
- package/cjs/abi/interfaces/BitcoinInterfaceAbi.d.ts +11 -0
- package/cjs/abi/interfaces/BitcoinInterfaceAbi.js +2 -0
- package/cjs/bitcoin/BitcoinAddress.d.ts +20 -0
- package/cjs/bitcoin/BitcoinAddress.js +116 -0
- package/cjs/bitcoin/UTXOs.d.ts +15 -0
- package/cjs/bitcoin/UTXOs.js +16 -0
- package/cjs/block/Block.d.ts +2 -3
- package/cjs/block/Block.js +3 -28
- package/cjs/block/interfaces/IBlock.d.ts +28 -0
- package/cjs/block/interfaces/IBlock.js +2 -0
- package/cjs/common/CommonTypes.d.ts +4 -0
- package/cjs/common/CommonTypes.js +2 -0
- package/cjs/contracts/CallResult.d.ts +13 -0
- package/cjs/contracts/CallResult.js +25 -0
- package/cjs/contracts/Contract.d.ts +28 -0
- package/cjs/contracts/Contract.js +212 -0
- package/cjs/contracts/ContractData.d.ts +15 -0
- package/cjs/contracts/ContractData.js +36 -0
- package/cjs/contracts/interfaces/IAccessList.d.ts +6 -0
- package/cjs/contracts/interfaces/IAccessList.js +2 -0
- package/cjs/contracts/interfaces/ICallResult.d.ts +11 -0
- package/cjs/contracts/interfaces/ICallResult.js +2 -0
- package/cjs/contracts/interfaces/IContract.d.ts +4 -0
- package/cjs/contracts/interfaces/IContract.js +2 -0
- package/cjs/contracts/interfaces/IRawContract.d.ts +13 -0
- package/cjs/contracts/interfaces/IRawContract.js +2 -0
- package/cjs/crypto/crypto.d.ts +2 -0
- package/cjs/crypto/crypto.js +8 -0
- package/cjs/index.d.ts +3 -11
- package/cjs/index.js +16 -11
- package/cjs/opnet.d.ts +36 -0
- package/cjs/opnet.js +54 -0
- package/cjs/providers/AbstractRpcProvider.d.ts +34 -0
- package/cjs/providers/AbstractRpcProvider.js +161 -0
- package/cjs/providers/JSONRpcProvider.d.ts +5 -9
- package/cjs/providers/JSONRpcProvider.js +4 -29
- package/cjs/providers/WebsocketRpcProvider.d.ts +8 -0
- package/cjs/providers/WebsocketRpcProvider.js +27 -0
- package/cjs/scripts/testContract.d.ts +1 -0
- package/cjs/scripts/testContract.js +30 -0
- package/cjs/scripts/testMethods.d.ts +1 -0
- package/cjs/scripts/testMethods.js +26 -0
- package/cjs/serialize/BigInt.d.ts +6 -0
- package/cjs/serialize/BigInt.js +5 -0
- package/cjs/storage/StoredValue.d.ts +10 -0
- package/cjs/storage/StoredValue.js +28 -0
- package/cjs/storage/interfaces/IStorageValue.d.ts +9 -0
- package/cjs/storage/interfaces/IStorageValue.js +2 -0
- package/cjs/transactions/DeploymentTransaction.d.ts +10 -1
- package/cjs/transactions/DeploymentTransaction.js +16 -0
- package/cjs/transactions/GenericTransaction.d.ts +1 -1
- package/cjs/transactions/InteractionTransaction.d.ts +1 -1
- package/cjs/transactions/Transaction.d.ts +1 -1
- package/cjs/transactions/Transaction.js +1 -1
- package/cjs/transactions/TransactionParser.d.ts +7 -0
- package/cjs/transactions/TransactionParser.js +32 -0
- package/cjs/transactions/TransactionReceipt.d.ts +10 -0
- package/cjs/transactions/TransactionReceipt.js +16 -0
- package/cjs/transactions/interfaces/ITransaction.d.ts +39 -0
- package/cjs/transactions/interfaces/ITransaction.js +2 -0
- package/cjs/transactions/interfaces/ITransactionReceipt.d.ts +8 -0
- package/cjs/transactions/interfaces/ITransactionReceipt.js +2 -0
- package/cjs/utils/BitcoinUtils.d.ts +4 -0
- package/cjs/utils/BitcoinUtils.js +14 -0
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/AbstractRpcProvider.html +15 -15
- package/docs/classes/BaseContract.html +187 -0
- package/docs/classes/BitcoinAddress.html +5 -2
- package/docs/classes/BitcoinInterface.html +182 -0
- package/docs/classes/BitcoinUtils.html +183 -0
- package/docs/classes/Block.html +5 -3
- package/docs/classes/CallResult.html +6 -2
- package/docs/classes/ContractData.html +4 -2
- package/docs/classes/DeploymentTransaction.html +4 -2
- package/docs/classes/GenericTransaction.html +4 -2
- package/docs/classes/IBaseContract.html +192 -0
- package/docs/classes/InteractionTransaction.html +3 -2
- package/docs/classes/JSONRpcProvider.html +14 -14
- package/docs/classes/StoredValue.html +4 -2
- package/docs/classes/TransactionBase.html +4 -2
- package/docs/classes/TransactionInput.html +3 -2
- package/docs/classes/TransactionOutput.html +3 -2
- package/docs/classes/TransactionParser.html +3 -2
- package/docs/classes/TransactionReceipt.html +3 -2
- package/docs/classes/UTXO.html +4 -2
- package/docs/classes/WebSocketRpcProvider.html +14 -14
- package/docs/enums/ABIDataTypes.html +183 -0
- package/docs/enums/BitcoinAbiTypes.html +178 -0
- package/docs/enums/OPNetTransactionTypes.html +2 -2
- package/docs/functions/getContract.html +180 -0
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +4 -5
- package/docs/interfaces/BaseContractProperties.html +176 -0
- package/docs/interfaces/BitcoinAbiValue.html +180 -0
- package/docs/interfaces/BitcoinInterfaceAbiBase.html +182 -0
- package/docs/interfaces/IAccessList.html +3 -1
- package/docs/interfaces/IAccessListItem.html +3 -1
- package/docs/interfaces/IBlock.html +5 -3
- package/docs/interfaces/IBlockCommon.html +5 -3
- package/docs/interfaces/ICallRequestError.html +4 -2
- package/docs/interfaces/ICallResultData.html +4 -2
- package/docs/interfaces/IContract.html +177 -0
- package/docs/interfaces/IDeploymentTransaction.html +4 -2
- package/docs/interfaces/IGenericTransaction.html +4 -2
- package/docs/interfaces/IInteractionTransaction.html +4 -2
- package/docs/interfaces/IRawContract.html +5 -2
- package/docs/interfaces/IStorageValue.html +4 -2
- package/docs/interfaces/ITransactionBase.html +4 -2
- package/docs/interfaces/ITransactionInput.html +3 -2
- package/docs/interfaces/ITransactionOutput.html +3 -2
- package/docs/interfaces/ITransactionReceipt.html +4 -2
- package/docs/interfaces/IUTXO.html +4 -2
- package/docs/modules.html +38 -24
- package/docs/types/BaseContractProperty.html +176 -0
- package/docs/types/BitcoinAddressLike.html +1 -1
- package/docs/types/BitcoinInterfaceAbi.html +174 -0
- package/docs/types/BlockHeaderChecksumProof.html +1 -1
- package/docs/types/DecodedCallResult.html +174 -0
- package/docs/types/ICallResult.html +2 -1
- package/docs/types/ITransaction.html +2 -1
- package/docs/types/PointerLike.html +1 -1
- package/docs/types/UTXOs.html +3 -1
- package/docs/variables/version.html +1 -1
- package/package.json +6 -4
- package/src/_version.ts +1 -1
- package/src/abi/BaseContractProperty.ts +8 -0
- package/src/abi/BitcoinAbiTypes.ts +9 -0
- package/src/abi/BitcoinInterface.ts +63 -0
- package/src/abi/interfaces/BaseContractProperties.ts +9 -0
- package/src/abi/interfaces/BitcoinAbiValue.ts +18 -0
- package/src/abi/interfaces/BitcoinInterfaceAbi.ts +19 -0
- package/src/bitcoin/BitcoinAddress.ts +5 -0
- package/src/bitcoin/UTXOs.ts +28 -26
- package/src/bitcoin/interfaces/IUTXO.ts +12 -0
- package/src/block/Block.ts +5 -0
- package/src/block/interfaces/IBlock.ts +46 -38
- package/src/common/CommonTypes.ts +16 -4
- package/src/contracts/CallResult.ts +34 -20
- package/src/contracts/Contract.ts +321 -0
- package/src/contracts/ContractData.ts +46 -41
- package/src/contracts/interfaces/IAccessList.ts +17 -7
- package/src/contracts/interfaces/ICallResult.ts +29 -15
- package/src/contracts/interfaces/IContract.ts +10 -0
- package/src/contracts/interfaces/IRawContract.ts +17 -12
- package/src/crypto/crypto-browser.js +71 -60
- package/src/opnet.ts +17 -0
- package/src/providers/AbstractRpcProvider.ts +352 -351
- package/src/scripts/testContract.ts +51 -0
- package/src/scripts/{test.ts → testMethods.ts} +52 -54
- package/src/scripts/test_abi.json +31 -0
- package/src/storage/StoredValue.ts +35 -30
- package/src/storage/interfaces/IStorageValue.ts +15 -10
- package/src/transactions/DeploymentTransaction.ts +41 -36
- package/src/transactions/GenericTransaction.ts +19 -12
- package/src/transactions/InteractionTransaction.ts +44 -40
- package/src/transactions/Transaction.ts +8 -0
- package/src/transactions/TransactionInput.ts +8 -0
- package/src/transactions/TransactionOutput.ts +8 -0
- package/src/transactions/TransactionParser.ts +47 -43
- package/src/transactions/TransactionReceipt.ts +22 -18
- package/src/transactions/interfaces/ITransaction.ts +78 -52
- package/src/transactions/interfaces/ITransactionReceipt.ts +14 -9
- package/src/utils/BitcoinUtils.ts +22 -0
- package/webpack.config.js +71 -75
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getContract = exports.BaseContract = exports.IBaseContract = void 0;
|
|
4
|
+
const bsi_binary_1 = require("@btc-vision/bsi-binary");
|
|
5
|
+
const BitcoinAbiTypes_js_1 = require("../abi/BitcoinAbiTypes.js");
|
|
6
|
+
const BitcoinInterface_js_1 = require("../abi/BitcoinInterface.js");
|
|
7
|
+
const internal = Symbol.for('_btc_internal');
|
|
8
|
+
const bitcoinAbiCoder = new bsi_binary_1.ABICoder();
|
|
9
|
+
class IBaseContract {
|
|
10
|
+
address;
|
|
11
|
+
interface;
|
|
12
|
+
provider;
|
|
13
|
+
[internal];
|
|
14
|
+
events = [];
|
|
15
|
+
constructor(address, abi, provider) {
|
|
16
|
+
this.address = address;
|
|
17
|
+
this.provider = provider;
|
|
18
|
+
this.interface = BitcoinInterface_js_1.BitcoinInterface.from(abi);
|
|
19
|
+
Object.defineProperty(this, internal, { value: {} });
|
|
20
|
+
this.defineInternalFunctions();
|
|
21
|
+
}
|
|
22
|
+
getFunction(name) {
|
|
23
|
+
const key = name;
|
|
24
|
+
return this[key];
|
|
25
|
+
}
|
|
26
|
+
defineInternalFunctions() {
|
|
27
|
+
for (const element of this.interface.abi) {
|
|
28
|
+
switch (element.type) {
|
|
29
|
+
case BitcoinAbiTypes_js_1.BitcoinAbiTypes.Function:
|
|
30
|
+
Object.defineProperty(this, element.name, {
|
|
31
|
+
value: this.callFunction(element).bind(this),
|
|
32
|
+
});
|
|
33
|
+
break;
|
|
34
|
+
case BitcoinAbiTypes_js_1.BitcoinAbiTypes.Event:
|
|
35
|
+
this.events.push(element);
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
encodeFunctionData(element, args) {
|
|
43
|
+
const writer = new bsi_binary_1.BinaryWriter();
|
|
44
|
+
const selector = Number('0x' + bitcoinAbiCoder.encodeSelector(element.name));
|
|
45
|
+
writer.writeSelector(selector);
|
|
46
|
+
if (args.length !== element.inputs.length) {
|
|
47
|
+
throw new Error('Invalid number of arguments provided');
|
|
48
|
+
}
|
|
49
|
+
if (!element.inputs || (element.inputs && element.inputs.length === 0)) {
|
|
50
|
+
return writer;
|
|
51
|
+
}
|
|
52
|
+
for (let i = 0; i < element.inputs.length; i++) {
|
|
53
|
+
this.encodeInput(writer, element.inputs[i], args[i]);
|
|
54
|
+
}
|
|
55
|
+
return writer;
|
|
56
|
+
}
|
|
57
|
+
encodeInput(writer, abi, value) {
|
|
58
|
+
const type = abi.type;
|
|
59
|
+
const name = abi.name;
|
|
60
|
+
switch (type) {
|
|
61
|
+
case bsi_binary_1.ABIDataTypes.UINT256:
|
|
62
|
+
if (typeof value !== 'bigint') {
|
|
63
|
+
throw new Error(`Expected value to be of type bigint (${name})`);
|
|
64
|
+
}
|
|
65
|
+
writer.writeU256(value);
|
|
66
|
+
break;
|
|
67
|
+
case bsi_binary_1.ABIDataTypes.BOOL:
|
|
68
|
+
if (typeof value !== 'boolean') {
|
|
69
|
+
throw new Error(`Expected value to be of type boolean (${name})`);
|
|
70
|
+
}
|
|
71
|
+
writer.writeBoolean(value);
|
|
72
|
+
break;
|
|
73
|
+
case bsi_binary_1.ABIDataTypes.STRING:
|
|
74
|
+
if (typeof value !== 'string') {
|
|
75
|
+
throw new Error(`Expected value to be of type string (${name})`);
|
|
76
|
+
}
|
|
77
|
+
writer.writeStringWithLength(value);
|
|
78
|
+
break;
|
|
79
|
+
case bsi_binary_1.ABIDataTypes.ADDRESS:
|
|
80
|
+
const address = value;
|
|
81
|
+
writer.writeAddress(address.toString());
|
|
82
|
+
break;
|
|
83
|
+
case bsi_binary_1.ABIDataTypes.TUPLE:
|
|
84
|
+
if (!(value instanceof Array)) {
|
|
85
|
+
throw new Error(`Expected value to be of type Array (${name})`);
|
|
86
|
+
}
|
|
87
|
+
writer.writeTuple(value);
|
|
88
|
+
break;
|
|
89
|
+
case bsi_binary_1.ABIDataTypes.UINT8:
|
|
90
|
+
if (typeof value !== 'number') {
|
|
91
|
+
throw new Error(`Expected value to be of type number (${name})`);
|
|
92
|
+
}
|
|
93
|
+
writer.writeU8(value);
|
|
94
|
+
break;
|
|
95
|
+
case bsi_binary_1.ABIDataTypes.UINT16:
|
|
96
|
+
if (typeof value !== 'number') {
|
|
97
|
+
throw new Error(`Expected value to be of type number (${name})`);
|
|
98
|
+
}
|
|
99
|
+
writer.writeU16(value);
|
|
100
|
+
break;
|
|
101
|
+
case bsi_binary_1.ABIDataTypes.UINT32:
|
|
102
|
+
if (typeof value !== 'number') {
|
|
103
|
+
throw new Error(`Expected value to be of type number (${name})`);
|
|
104
|
+
}
|
|
105
|
+
writer.writeU32(value);
|
|
106
|
+
break;
|
|
107
|
+
case bsi_binary_1.ABIDataTypes.BYTES32:
|
|
108
|
+
if (!(value instanceof Uint8Array)) {
|
|
109
|
+
throw new Error(`Expected value to be of type Uint8Array (${name})`);
|
|
110
|
+
}
|
|
111
|
+
writer.writeBytes(value);
|
|
112
|
+
break;
|
|
113
|
+
default:
|
|
114
|
+
throw new Error(`Unsupported type: ${type} (${name})`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
decodeOutput(abi, reader) {
|
|
118
|
+
const result = [];
|
|
119
|
+
for (let i = 0; i < abi.length; i++) {
|
|
120
|
+
const type = abi[i].type;
|
|
121
|
+
const name = abi[i].name;
|
|
122
|
+
switch (type) {
|
|
123
|
+
case bsi_binary_1.ABIDataTypes.UINT256:
|
|
124
|
+
result.push(reader.readU256());
|
|
125
|
+
break;
|
|
126
|
+
case bsi_binary_1.ABIDataTypes.BOOL:
|
|
127
|
+
result.push(reader.readBoolean());
|
|
128
|
+
break;
|
|
129
|
+
case bsi_binary_1.ABIDataTypes.STRING:
|
|
130
|
+
result.push(reader.readStringWithLength());
|
|
131
|
+
break;
|
|
132
|
+
case bsi_binary_1.ABIDataTypes.ADDRESS:
|
|
133
|
+
result.push(reader.readAddress());
|
|
134
|
+
break;
|
|
135
|
+
case bsi_binary_1.ABIDataTypes.TUPLE:
|
|
136
|
+
result.push(reader.readTuple());
|
|
137
|
+
break;
|
|
138
|
+
case bsi_binary_1.ABIDataTypes.UINT8:
|
|
139
|
+
result.push(reader.readU8());
|
|
140
|
+
break;
|
|
141
|
+
case bsi_binary_1.ABIDataTypes.UINT16:
|
|
142
|
+
result.push(reader.readU16());
|
|
143
|
+
break;
|
|
144
|
+
case bsi_binary_1.ABIDataTypes.UINT32:
|
|
145
|
+
result.push(reader.readU32());
|
|
146
|
+
break;
|
|
147
|
+
case bsi_binary_1.ABIDataTypes.BYTES32:
|
|
148
|
+
result.push(reader.readBytes(32));
|
|
149
|
+
break;
|
|
150
|
+
default:
|
|
151
|
+
throw new Error(`Unsupported type: ${type} (${name})`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
callFunction(element) {
|
|
157
|
+
return async (...args) => {
|
|
158
|
+
const data = this.encodeFunctionData(element, args);
|
|
159
|
+
const response = await this.provider.call(this.address, Buffer.from(data.getBuffer()));
|
|
160
|
+
if ('error' in response) {
|
|
161
|
+
return response;
|
|
162
|
+
}
|
|
163
|
+
const decoded = element.outputs
|
|
164
|
+
? this.decodeOutput(element.outputs, response.result)
|
|
165
|
+
: [];
|
|
166
|
+
response.setDecoded(decoded);
|
|
167
|
+
return response;
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.IBaseContract = IBaseContract;
|
|
172
|
+
class BaseContract extends IBaseContract {
|
|
173
|
+
constructor(address, abi, provider) {
|
|
174
|
+
super(address, abi, provider);
|
|
175
|
+
return this.proxify();
|
|
176
|
+
}
|
|
177
|
+
proxify() {
|
|
178
|
+
return new Proxy(this, {
|
|
179
|
+
get: (target, prop, receiver) => {
|
|
180
|
+
if (typeof prop === 'symbol' || prop in target) {
|
|
181
|
+
return Reflect.get(target, prop, receiver);
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
return this.getFunction(prop);
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
if (!(error instanceof Error)) {
|
|
188
|
+
throw new Error(`Something went wrong when trying to get the function: ${error}`);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
has: (target, prop) => {
|
|
196
|
+
if (typeof prop === 'symbol' || prop in target) {
|
|
197
|
+
return Reflect.has(target, prop);
|
|
198
|
+
}
|
|
199
|
+
return target.interface.hasFunction(prop);
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
exports.BaseContract = BaseContract;
|
|
205
|
+
function contractBase() {
|
|
206
|
+
return BaseContract;
|
|
207
|
+
}
|
|
208
|
+
function getContract(address, abi, provider) {
|
|
209
|
+
const base = contractBase();
|
|
210
|
+
return new base(address, abi, provider);
|
|
211
|
+
}
|
|
212
|
+
exports.getContract = getContract;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IRawContract } from './interfaces/IRawContract.js';
|
|
3
|
+
export declare class ContractData implements IRawContract {
|
|
4
|
+
readonly contractAddress: string;
|
|
5
|
+
readonly virtualAddress: string;
|
|
6
|
+
readonly bytecode: Buffer;
|
|
7
|
+
readonly wasCompressed: boolean;
|
|
8
|
+
readonly deployedTransactionId: string;
|
|
9
|
+
readonly deployedTransactionHash: string;
|
|
10
|
+
readonly deployerPubKey: Buffer;
|
|
11
|
+
readonly contractSeed: Buffer;
|
|
12
|
+
readonly contractSaltHash: Buffer;
|
|
13
|
+
readonly deployerAddress: string;
|
|
14
|
+
constructor(raw: IRawContract);
|
|
15
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContractData = void 0;
|
|
4
|
+
class ContractData {
|
|
5
|
+
contractAddress;
|
|
6
|
+
virtualAddress;
|
|
7
|
+
bytecode;
|
|
8
|
+
wasCompressed;
|
|
9
|
+
deployedTransactionId;
|
|
10
|
+
deployedTransactionHash;
|
|
11
|
+
deployerPubKey;
|
|
12
|
+
contractSeed;
|
|
13
|
+
contractSaltHash;
|
|
14
|
+
deployerAddress;
|
|
15
|
+
constructor(raw) {
|
|
16
|
+
this.contractAddress = raw.contractAddress;
|
|
17
|
+
this.virtualAddress = raw.virtualAddress;
|
|
18
|
+
this.bytecode = Buffer.isBuffer(raw.bytecode)
|
|
19
|
+
? raw.bytecode
|
|
20
|
+
: Buffer.from(raw.bytecode, 'base64');
|
|
21
|
+
this.wasCompressed = raw.wasCompressed;
|
|
22
|
+
this.deployedTransactionId = raw.deployedTransactionId;
|
|
23
|
+
this.deployedTransactionHash = raw.deployedTransactionHash;
|
|
24
|
+
this.deployerPubKey = Buffer.isBuffer(raw.deployerPubKey)
|
|
25
|
+
? raw.deployerPubKey
|
|
26
|
+
: Buffer.from(raw.deployerPubKey, 'base64');
|
|
27
|
+
this.contractSeed = Buffer.isBuffer(raw.contractSeed)
|
|
28
|
+
? raw.contractSeed
|
|
29
|
+
: Buffer.from(raw.contractSeed, 'base64');
|
|
30
|
+
this.contractSaltHash = Buffer.isBuffer(raw.contractSaltHash)
|
|
31
|
+
? raw.contractSaltHash
|
|
32
|
+
: Buffer.from(raw.contractSaltHash, 'base64');
|
|
33
|
+
this.deployerAddress = raw.deployerAddress;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.ContractData = ContractData;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BinaryReader, NetEvent } from '@btc-vision/bsi-binary';
|
|
2
|
+
import { IAccessList } from './IAccessList.js';
|
|
3
|
+
export interface ICallRequestError {
|
|
4
|
+
readonly error: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ICallResultData {
|
|
7
|
+
readonly result: string | BinaryReader;
|
|
8
|
+
readonly events: NetEvent[];
|
|
9
|
+
readonly accessList: IAccessList;
|
|
10
|
+
}
|
|
11
|
+
export type ICallResult = ICallRequestError | ICallResultData;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export interface IRawContract {
|
|
3
|
+
readonly contractAddress: string;
|
|
4
|
+
readonly virtualAddress: string;
|
|
5
|
+
readonly bytecode: Buffer | string;
|
|
6
|
+
readonly wasCompressed: boolean;
|
|
7
|
+
readonly deployedTransactionId: string;
|
|
8
|
+
readonly deployedTransactionHash: string;
|
|
9
|
+
readonly deployerPubKey: Buffer | string;
|
|
10
|
+
readonly contractSeed: Buffer | string;
|
|
11
|
+
readonly contractSaltHash: Buffer | string;
|
|
12
|
+
readonly deployerAddress: string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randomBytes = exports.pbkdf2Sync = exports.createHmac = exports.createHash = void 0;
|
|
4
|
+
var crypto_1 = require("crypto");
|
|
5
|
+
Object.defineProperty(exports, "createHash", { enumerable: true, get: function () { return crypto_1.createHash; } });
|
|
6
|
+
Object.defineProperty(exports, "createHmac", { enumerable: true, get: function () { return crypto_1.createHmac; } });
|
|
7
|
+
Object.defineProperty(exports, "pbkdf2Sync", { enumerable: true, get: function () { return crypto_1.pbkdf2Sync; } });
|
|
8
|
+
Object.defineProperty(exports, "randomBytes", { enumerable: true, get: function () { return crypto_1.randomBytes; } });
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './transactions/GenericTransaction.js';
|
|
5
|
-
export * from './transactions/InteractionTransaction.js';
|
|
6
|
-
export * from './transactions/Transaction.js';
|
|
7
|
-
export * from './transactions/TransactionInput.js';
|
|
8
|
-
export * from './transactions/TransactionOutput.js';
|
|
9
|
-
export * from './providers/JSONRpcProvider.js';
|
|
10
|
-
export * from './block/Block.js';
|
|
11
|
-
export * from './interfaces/blocks/IBlock.js';
|
|
1
|
+
import * as opnet from './opnet.js';
|
|
2
|
+
export { opnet };
|
|
3
|
+
export * from './opnet.js';
|
package/cjs/index.js
CHANGED
|
@@ -10,18 +10,23 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
13
25
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
27
|
};
|
|
16
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
__exportStar(require("./
|
|
21
|
-
__exportStar(require("./transactions/InteractionTransaction.js"), exports);
|
|
22
|
-
__exportStar(require("./transactions/Transaction.js"), exports);
|
|
23
|
-
__exportStar(require("./transactions/TransactionInput.js"), exports);
|
|
24
|
-
__exportStar(require("./transactions/TransactionOutput.js"), exports);
|
|
25
|
-
__exportStar(require("./providers/JSONRpcProvider.js"), exports);
|
|
26
|
-
__exportStar(require("./block/Block.js"), exports);
|
|
27
|
-
__exportStar(require("./interfaces/blocks/IBlock.js"), exports);
|
|
29
|
+
exports.opnet = void 0;
|
|
30
|
+
const opnet = __importStar(require("./opnet.js"));
|
|
31
|
+
exports.opnet = opnet;
|
|
32
|
+
__exportStar(require("./opnet.js"), exports);
|
package/cjs/opnet.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export { version } from './_version.js';
|
|
2
|
+
export * from './interfaces/opnet/OPNetTransactionTypes.js';
|
|
3
|
+
export * from './transactions/DeploymentTransaction.js';
|
|
4
|
+
export * from './transactions/GenericTransaction.js';
|
|
5
|
+
export * from './transactions/InteractionTransaction.js';
|
|
6
|
+
export * from './transactions/Transaction.js';
|
|
7
|
+
export * from './transactions/TransactionInput.js';
|
|
8
|
+
export * from './transactions/TransactionOutput.js';
|
|
9
|
+
export * from './providers/JSONRpcProvider.js';
|
|
10
|
+
export * from './providers/AbstractRpcProvider.js';
|
|
11
|
+
export * from './providers/WebsocketRpcProvider.js';
|
|
12
|
+
export * from './block/Block.js';
|
|
13
|
+
export * from './transactions/TransactionParser.js';
|
|
14
|
+
export * from './contracts/ContractData.js';
|
|
15
|
+
export * from './contracts/CallResult.js';
|
|
16
|
+
export * from './contracts/Contract.js';
|
|
17
|
+
export * from './contracts/interfaces/IContract.js';
|
|
18
|
+
export * from './contracts/interfaces/ICallResult.js';
|
|
19
|
+
export * from './contracts/interfaces/IAccessList.js';
|
|
20
|
+
export * from './abi/BitcoinInterface.js';
|
|
21
|
+
export * from './abi/interfaces/BitcoinInterfaceAbi.js';
|
|
22
|
+
export * from './abi/interfaces/BitcoinAbiValue.js';
|
|
23
|
+
export * from './abi/BitcoinAbiTypes.js';
|
|
24
|
+
export * from './abi/interfaces/BaseContractProperties.js';
|
|
25
|
+
export * from './abi/BaseContractProperty.js';
|
|
26
|
+
export * from './utils/BitcoinUtils.js';
|
|
27
|
+
export * from './storage/StoredValue.js';
|
|
28
|
+
export * from './storage/interfaces/IStorageValue.js';
|
|
29
|
+
export * from './block/interfaces/IBlock.js';
|
|
30
|
+
export * from './transactions/interfaces/ITransaction.js';
|
|
31
|
+
export * from './transactions/interfaces/ITransactionReceipt.js';
|
|
32
|
+
export * from './transactions/TransactionReceipt.js';
|
|
33
|
+
export * from './contracts/interfaces/IRawContract.js';
|
|
34
|
+
export * from './common/CommonTypes.js';
|
|
35
|
+
export * from './bitcoin/BitcoinAddress.js';
|
|
36
|
+
export * from './bitcoin/UTXOs.js';
|
package/cjs/opnet.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.version = void 0;
|
|
18
|
+
var _version_js_1 = require("./_version.js");
|
|
19
|
+
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return _version_js_1.version; } });
|
|
20
|
+
__exportStar(require("./interfaces/opnet/OPNetTransactionTypes.js"), exports);
|
|
21
|
+
__exportStar(require("./transactions/DeploymentTransaction.js"), exports);
|
|
22
|
+
__exportStar(require("./transactions/GenericTransaction.js"), exports);
|
|
23
|
+
__exportStar(require("./transactions/InteractionTransaction.js"), exports);
|
|
24
|
+
__exportStar(require("./transactions/Transaction.js"), exports);
|
|
25
|
+
__exportStar(require("./transactions/TransactionInput.js"), exports);
|
|
26
|
+
__exportStar(require("./transactions/TransactionOutput.js"), exports);
|
|
27
|
+
__exportStar(require("./providers/JSONRpcProvider.js"), exports);
|
|
28
|
+
__exportStar(require("./providers/AbstractRpcProvider.js"), exports);
|
|
29
|
+
__exportStar(require("./providers/WebsocketRpcProvider.js"), exports);
|
|
30
|
+
__exportStar(require("./block/Block.js"), exports);
|
|
31
|
+
__exportStar(require("./transactions/TransactionParser.js"), exports);
|
|
32
|
+
__exportStar(require("./contracts/ContractData.js"), exports);
|
|
33
|
+
__exportStar(require("./contracts/CallResult.js"), exports);
|
|
34
|
+
__exportStar(require("./contracts/Contract.js"), exports);
|
|
35
|
+
__exportStar(require("./contracts/interfaces/IContract.js"), exports);
|
|
36
|
+
__exportStar(require("./contracts/interfaces/ICallResult.js"), exports);
|
|
37
|
+
__exportStar(require("./contracts/interfaces/IAccessList.js"), exports);
|
|
38
|
+
__exportStar(require("./abi/BitcoinInterface.js"), exports);
|
|
39
|
+
__exportStar(require("./abi/interfaces/BitcoinInterfaceAbi.js"), exports);
|
|
40
|
+
__exportStar(require("./abi/interfaces/BitcoinAbiValue.js"), exports);
|
|
41
|
+
__exportStar(require("./abi/BitcoinAbiTypes.js"), exports);
|
|
42
|
+
__exportStar(require("./abi/interfaces/BaseContractProperties.js"), exports);
|
|
43
|
+
__exportStar(require("./abi/BaseContractProperty.js"), exports);
|
|
44
|
+
__exportStar(require("./utils/BitcoinUtils.js"), exports);
|
|
45
|
+
__exportStar(require("./storage/StoredValue.js"), exports);
|
|
46
|
+
__exportStar(require("./storage/interfaces/IStorageValue.js"), exports);
|
|
47
|
+
__exportStar(require("./block/interfaces/IBlock.js"), exports);
|
|
48
|
+
__exportStar(require("./transactions/interfaces/ITransaction.js"), exports);
|
|
49
|
+
__exportStar(require("./transactions/interfaces/ITransactionReceipt.js"), exports);
|
|
50
|
+
__exportStar(require("./transactions/TransactionReceipt.js"), exports);
|
|
51
|
+
__exportStar(require("./contracts/interfaces/IRawContract.js"), exports);
|
|
52
|
+
__exportStar(require("./common/CommonTypes.js"), exports);
|
|
53
|
+
__exportStar(require("./bitcoin/BitcoinAddress.js"), exports);
|
|
54
|
+
__exportStar(require("./bitcoin/UTXOs.js"), exports);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import '../serialize/BigInt.js';
|
|
3
|
+
import { Network } from 'bitcoinjs-lib';
|
|
4
|
+
import { BigNumberish, BlockTag, JsonRpcApiProvider } from 'ethers';
|
|
5
|
+
import { Block } from '../block/Block.js';
|
|
6
|
+
import { BitcoinAddressLike } from '../common/CommonTypes.js';
|
|
7
|
+
import { CallResult } from '../contracts/CallResult.js';
|
|
8
|
+
import { ContractData } from '../contracts/ContractData.js';
|
|
9
|
+
import { ICallRequestError } from '../contracts/interfaces/ICallResult.js';
|
|
10
|
+
import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
|
|
11
|
+
import { StoredValue } from '../storage/StoredValue.js';
|
|
12
|
+
import { ITransactionReceipt } from '../transactions/interfaces/ITransactionReceipt.js';
|
|
13
|
+
import { TransactionBase } from '../transactions/Transaction.js';
|
|
14
|
+
export declare abstract class AbstractRpcProvider {
|
|
15
|
+
protected abstract readonly provider: JsonRpcApiProvider;
|
|
16
|
+
private nextId;
|
|
17
|
+
protected constructor();
|
|
18
|
+
getBlockNumber(): Promise<number>;
|
|
19
|
+
getBlock(blockNumberOrHash: BlockTag, prefetchTxs?: boolean): Promise<Block>;
|
|
20
|
+
getBlockByHash(blockHash: string): Promise<Block>;
|
|
21
|
+
getBalance(addressLike: BitcoinAddressLike): Promise<bigint>;
|
|
22
|
+
getUXTOs(address: BitcoinAddressLike, optimize?: boolean): Promise<unknown>;
|
|
23
|
+
getTransaction(txHash: string): Promise<TransactionBase<OPNetTransactionTypes>>;
|
|
24
|
+
getTransactionReceipt(txHash: string): Promise<ITransactionReceipt>;
|
|
25
|
+
getNetwork(): Promise<Network>;
|
|
26
|
+
getCode(address: BitcoinAddressLike, onlyBytecode?: boolean): Promise<ContractData | Buffer>;
|
|
27
|
+
getStorageAt(address: BitcoinAddressLike, rawPointer: bigint | string, proofs?: boolean, height?: BigNumberish): Promise<StoredValue>;
|
|
28
|
+
call(to: BitcoinAddressLike, data: Buffer | string, from?: BitcoinAddressLike, height?: BigNumberish): Promise<CallResult | ICallRequestError>;
|
|
29
|
+
protected abstract providerUrl(url: string): string;
|
|
30
|
+
private bufferToHex;
|
|
31
|
+
private bigintToBase64;
|
|
32
|
+
private callPayloadSingle;
|
|
33
|
+
private buildJsonRpcPayload;
|
|
34
|
+
}
|