opnet 1.2.16 → 1.2.18
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/contracts/Contract.d.ts +1 -0
- package/browser/contracts/TypeToStr.d.ts +4 -0
- package/browser/index.js +1 -1
- package/browser/opnet.d.ts +1 -0
- package/browser/transactions/Transaction.d.ts +1 -0
- package/browser/transactions/interfaces/ITransaction.d.ts +1 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/contracts/CallResult.js +4 -2
- package/build/contracts/Contract.d.ts +1 -0
- package/build/contracts/Contract.js +22 -1
- package/build/contracts/TypeToStr.d.ts +4 -0
- package/build/contracts/TypeToStr.js +25 -0
- package/build/opnet.d.ts +1 -0
- package/build/opnet.js +1 -0
- package/build/transactions/Transaction.d.ts +1 -0
- package/build/transactions/Transaction.js +2 -0
- package/build/transactions/interfaces/ITransaction.d.ts +1 -0
- package/package.json +3 -2
- package/src/_version.ts +1 -1
- package/src/contracts/CallResult.ts +4 -2
- package/src/contracts/Contract.ts +29 -1
- package/src/contracts/TypeToStr.ts +26 -0
- package/src/opnet.ts +1 -0
- package/src/transactions/Transaction.ts +6 -0
- package/src/transactions/interfaces/ITransaction.ts +5 -0
package/browser/opnet.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export * from './contracts/interfaces/ICallResult.js';
|
|
|
29
29
|
export * from './contracts/interfaces/IContract.js';
|
|
30
30
|
export * from './contracts/OPNetEvent.js';
|
|
31
31
|
export * from './contracts/interfaces/SimulatedTransaction.js';
|
|
32
|
+
export * from './contracts/TypeToStr.js';
|
|
32
33
|
export * from './abi/BitcoinAbiTypes.js';
|
|
33
34
|
export * from './abi/BitcoinInterface.js';
|
|
34
35
|
export * from './abi/interfaces/BaseContractProperties.js';
|
|
@@ -11,6 +11,7 @@ export declare abstract class TransactionBase<T extends OPNetTransactionTypes> e
|
|
|
11
11
|
readonly hash: string;
|
|
12
12
|
readonly index: number;
|
|
13
13
|
readonly burnedBitcoin: BigNumberish;
|
|
14
|
+
readonly priorityFee: BigNumberish;
|
|
14
15
|
readonly inputs: TransactionInput[];
|
|
15
16
|
readonly outputs: TransactionOutput[];
|
|
16
17
|
readonly OPNetType: T;
|
|
@@ -11,6 +11,7 @@ export interface ITransactionBase<T extends OPNetTransactionTypes> extends ITran
|
|
|
11
11
|
readonly hash: string;
|
|
12
12
|
readonly index: number;
|
|
13
13
|
readonly burnedBitcoin: string | BigNumberish;
|
|
14
|
+
readonly priorityFee: string | BigNumberish;
|
|
14
15
|
readonly revert?: string | Buffer;
|
|
15
16
|
readonly inputs: ITransactionInput[] | TransactionInput[];
|
|
16
17
|
readonly outputs: ITransactionOutput[] | TransactionOutput[];
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.2.
|
|
1
|
+
export declare const version = "1.2.18";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.2.
|
|
1
|
+
export const version = '1.2.18';
|
|
@@ -41,16 +41,18 @@ export class CallResult {
|
|
|
41
41
|
if (this.revert) {
|
|
42
42
|
throw new Error(`Can not send transaction! Simulation reverted: ${this.revert}`);
|
|
43
43
|
}
|
|
44
|
-
const priorityFee =
|
|
44
|
+
const priorityFee = interactionParams.priorityFee || 0n;
|
|
45
|
+
const totalFee = this.estimatedSatGas + priorityFee;
|
|
45
46
|
try {
|
|
46
47
|
const UTXOs = interactionParams.utxos ||
|
|
47
|
-
(await this.#fetchUTXOs(
|
|
48
|
+
(await this.#fetchUTXOs(totalFee + interactionParams.maximumAllowedSatToSpend, interactionParams));
|
|
48
49
|
if (!UTXOs || UTXOs.length === 0) {
|
|
49
50
|
throw new Error('No UTXOs found');
|
|
50
51
|
}
|
|
51
52
|
const params = {
|
|
52
53
|
calldata: this.calldata,
|
|
53
54
|
priorityFee: priorityFee,
|
|
55
|
+
gasSatFee: this.estimatedSatGas,
|
|
54
56
|
feeRate: interactionParams.feeRate || 10,
|
|
55
57
|
from: interactionParams.refundTo,
|
|
56
58
|
signer: interactionParams.signer,
|
|
@@ -45,6 +45,7 @@ export declare abstract class IBaseContract<T extends BaseContractProperties> im
|
|
|
45
45
|
setSimulatedHeight(height: bigint | undefined): void;
|
|
46
46
|
protected getFunction(name: symbol | string): CallResult | undefined | string | number | symbol | Address | Network | (() => Promise<BlockGasParameters>) | ((functionName: string, args: unknown[]) => Buffer);
|
|
47
47
|
private defineInternalFunctions;
|
|
48
|
+
private getSelector;
|
|
48
49
|
private encodeFunctionData;
|
|
49
50
|
private encodeInput;
|
|
50
51
|
private decodeOutput;
|
|
@@ -2,6 +2,7 @@ import { ABICoder, ABIDataTypes, AddressVerificator, BinaryReader, BinaryWriter,
|
|
|
2
2
|
import { BitcoinAbiTypes } from '../abi/BitcoinAbiTypes.js';
|
|
3
3
|
import { BitcoinInterface } from '../abi/BitcoinInterface.js';
|
|
4
4
|
import { OPNetEvent } from './OPNetEvent.js';
|
|
5
|
+
import { AbiTypeToStr } from './TypeToStr.js';
|
|
5
6
|
const internal = Symbol.for('_btc_internal');
|
|
6
7
|
const bitcoinAbiCoder = new ABICoder();
|
|
7
8
|
export class IBaseContract {
|
|
@@ -121,9 +122,29 @@ export class IBaseContract {
|
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
}
|
|
125
|
+
getSelector(element) {
|
|
126
|
+
let name = element.name;
|
|
127
|
+
if (element.inputs && element.inputs.length) {
|
|
128
|
+
name += '(';
|
|
129
|
+
for (let i = 0; i < element.inputs.length; i++) {
|
|
130
|
+
const input = element.inputs[i];
|
|
131
|
+
const str = AbiTypeToStr[input.type];
|
|
132
|
+
if (!str) {
|
|
133
|
+
throw new Error(`Unsupported type: ${input.type}`);
|
|
134
|
+
}
|
|
135
|
+
if (i > 0) {
|
|
136
|
+
name += ',';
|
|
137
|
+
}
|
|
138
|
+
name += str;
|
|
139
|
+
}
|
|
140
|
+
name += ')';
|
|
141
|
+
}
|
|
142
|
+
return name;
|
|
143
|
+
}
|
|
124
144
|
encodeFunctionData(element, args) {
|
|
125
145
|
const writer = new BinaryWriter();
|
|
126
|
-
const
|
|
146
|
+
const selectorStr = this.getSelector(element);
|
|
147
|
+
const selector = Number('0x' + bitcoinAbiCoder.encodeSelector(selectorStr));
|
|
127
148
|
writer.writeSelector(selector);
|
|
128
149
|
if (args.length !== (element.inputs?.length ?? 0)) {
|
|
129
150
|
throw new Error('Invalid number of arguments provided');
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ABIDataTypes } from '@btc-vision/transaction';
|
|
2
|
+
export const AbiTypeToStr = {
|
|
3
|
+
[ABIDataTypes.ADDRESS]: 'address',
|
|
4
|
+
[ABIDataTypes.BOOL]: 'bool',
|
|
5
|
+
[ABIDataTypes.BYTES]: 'bytes',
|
|
6
|
+
[ABIDataTypes.UINT256]: 'uint256',
|
|
7
|
+
[ABIDataTypes.UINT128]: 'uint128',
|
|
8
|
+
[ABIDataTypes.UINT64]: 'uint64',
|
|
9
|
+
[ABIDataTypes.UINT32]: 'uint32',
|
|
10
|
+
[ABIDataTypes.UINT16]: 'uint16',
|
|
11
|
+
[ABIDataTypes.UINT8]: 'uint8',
|
|
12
|
+
[ABIDataTypes.STRING]: 'string',
|
|
13
|
+
[ABIDataTypes.BYTES32]: 'bytes32',
|
|
14
|
+
[ABIDataTypes.ADDRESS_UINT256_TUPLE]: 'tuple(address,uint256)',
|
|
15
|
+
[ABIDataTypes.ARRAY_OF_ADDRESSES]: 'address[]',
|
|
16
|
+
[ABIDataTypes.ARRAY_OF_UINT256]: 'uint256[]',
|
|
17
|
+
[ABIDataTypes.ARRAY_OF_UINT128]: 'uint128[]',
|
|
18
|
+
[ABIDataTypes.ARRAY_OF_UINT64]: 'uint64[]',
|
|
19
|
+
[ABIDataTypes.ARRAY_OF_UINT32]: 'uint32[]',
|
|
20
|
+
[ABIDataTypes.ARRAY_OF_UINT16]: 'uint16[]',
|
|
21
|
+
[ABIDataTypes.ARRAY_OF_UINT8]: 'uint8[]',
|
|
22
|
+
[ABIDataTypes.ARRAY_OF_BYTES]: 'bytes[]',
|
|
23
|
+
[ABIDataTypes.ARRAY_OF_STRING]: 'string[]',
|
|
24
|
+
[ABIDataTypes.TUPLE]: 'tuple256',
|
|
25
|
+
};
|
package/build/opnet.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export * from './contracts/interfaces/ICallResult.js';
|
|
|
29
29
|
export * from './contracts/interfaces/IContract.js';
|
|
30
30
|
export * from './contracts/OPNetEvent.js';
|
|
31
31
|
export * from './contracts/interfaces/SimulatedTransaction.js';
|
|
32
|
+
export * from './contracts/TypeToStr.js';
|
|
32
33
|
export * from './abi/BitcoinAbiTypes.js';
|
|
33
34
|
export * from './abi/BitcoinInterface.js';
|
|
34
35
|
export * from './abi/interfaces/BaseContractProperties.js';
|
package/build/opnet.js
CHANGED
|
@@ -29,6 +29,7 @@ export * from './contracts/interfaces/ICallResult.js';
|
|
|
29
29
|
export * from './contracts/interfaces/IContract.js';
|
|
30
30
|
export * from './contracts/OPNetEvent.js';
|
|
31
31
|
export * from './contracts/interfaces/SimulatedTransaction.js';
|
|
32
|
+
export * from './contracts/TypeToStr.js';
|
|
32
33
|
export * from './abi/BitcoinAbiTypes.js';
|
|
33
34
|
export * from './abi/BitcoinInterface.js';
|
|
34
35
|
export * from './abi/interfaces/BaseContractProperties.js';
|
|
@@ -11,6 +11,7 @@ export declare abstract class TransactionBase<T extends OPNetTransactionTypes> e
|
|
|
11
11
|
readonly hash: string;
|
|
12
12
|
readonly index: number;
|
|
13
13
|
readonly burnedBitcoin: BigNumberish;
|
|
14
|
+
readonly priorityFee: BigNumberish;
|
|
14
15
|
readonly inputs: TransactionInput[];
|
|
15
16
|
readonly outputs: TransactionOutput[];
|
|
16
17
|
readonly OPNetType: T;
|
|
@@ -6,6 +6,7 @@ export class TransactionBase extends TransactionReceipt {
|
|
|
6
6
|
hash;
|
|
7
7
|
index;
|
|
8
8
|
burnedBitcoin;
|
|
9
|
+
priorityFee;
|
|
9
10
|
inputs;
|
|
10
11
|
outputs;
|
|
11
12
|
OPNetType;
|
|
@@ -22,6 +23,7 @@ export class TransactionBase extends TransactionReceipt {
|
|
|
22
23
|
this.hash = transaction.hash;
|
|
23
24
|
this.index = transaction.index;
|
|
24
25
|
this.burnedBitcoin = BigInt(transaction.burnedBitcoin) || 0n;
|
|
26
|
+
this.priorityFee = BigInt(transaction.priorityFee) || 0n;
|
|
25
27
|
this.inputs = transaction.inputs.map((input) => new TransactionInput(input));
|
|
26
28
|
this.outputs = transaction.outputs.map((output) => new TransactionOutput(output));
|
|
27
29
|
this.OPNetType = transaction.OPNetType;
|
|
@@ -11,6 +11,7 @@ export interface ITransactionBase<T extends OPNetTransactionTypes> extends ITran
|
|
|
11
11
|
readonly hash: string;
|
|
12
12
|
readonly index: number;
|
|
13
13
|
readonly burnedBitcoin: string | BigNumberish;
|
|
14
|
+
readonly priorityFee: string | BigNumberish;
|
|
14
15
|
readonly revert?: string | Buffer;
|
|
15
16
|
readonly inputs: ITransactionInput[] | TransactionInput[];
|
|
16
17
|
readonly outputs: ITransactionOutput[] | TransactionOutput[];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opnet",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.18",
|
|
5
5
|
"author": "OP_NET",
|
|
6
6
|
"description": "The perfect library for building Bitcoin-based applications.",
|
|
7
7
|
"engines": {
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"@babel/preset-typescript": "^7.26.0",
|
|
71
71
|
"@eslint/js": "^9.17.0",
|
|
72
72
|
"@types/node": "^22.10.5",
|
|
73
|
+
"@types/sha.js": "^2.4.4",
|
|
73
74
|
"@types/ws": "^8.5.13",
|
|
74
75
|
"assert": "^2.1.0",
|
|
75
76
|
"babel-loader": "^9.2.1",
|
|
@@ -101,7 +102,7 @@
|
|
|
101
102
|
"@bitcoinerlab/secp256k1": "^1.2.0",
|
|
102
103
|
"@btc-vision/bitcoin": "^6.3.3",
|
|
103
104
|
"@btc-vision/bitcoin-rpc": "^1.0.0",
|
|
104
|
-
"@btc-vision/transaction": "^1.2.
|
|
105
|
+
"@btc-vision/transaction": "^1.2.7",
|
|
105
106
|
"@noble/hashes": "^1.7.0",
|
|
106
107
|
"bignumber.js": "^9.1.2",
|
|
107
108
|
"buffer": "^6.0.3",
|
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.2.
|
|
1
|
+
export const version = '1.2.18';
|
|
@@ -110,12 +110,13 @@ export class CallResult<
|
|
|
110
110
|
throw new Error(`Can not send transaction! Simulation reverted: ${this.revert}`);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
const priorityFee
|
|
113
|
+
const priorityFee = interactionParams.priorityFee || 0n;
|
|
114
|
+
const totalFee: bigint = this.estimatedSatGas + priorityFee;
|
|
114
115
|
try {
|
|
115
116
|
const UTXOs: UTXO[] =
|
|
116
117
|
interactionParams.utxos ||
|
|
117
118
|
(await this.#fetchUTXOs(
|
|
118
|
-
|
|
119
|
+
totalFee + interactionParams.maximumAllowedSatToSpend,
|
|
119
120
|
interactionParams,
|
|
120
121
|
));
|
|
121
122
|
|
|
@@ -126,6 +127,7 @@ export class CallResult<
|
|
|
126
127
|
const params: IInteractionParameters | InteractionParametersWithoutSigner = {
|
|
127
128
|
calldata: this.calldata,
|
|
128
129
|
priorityFee: priorityFee,
|
|
130
|
+
gasSatFee: this.estimatedSatGas,
|
|
129
131
|
feeRate: interactionParams.feeRate || 10,
|
|
130
132
|
from: interactionParams.refundTo,
|
|
131
133
|
signer: interactionParams.signer,
|
|
@@ -27,6 +27,7 @@ import { IAccessList } from './interfaces/IAccessList.js';
|
|
|
27
27
|
import { IContract } from './interfaces/IContract.js';
|
|
28
28
|
import { ParsedSimulatedTransaction } from './interfaces/SimulatedTransaction.js';
|
|
29
29
|
import { OPNetEvent } from './OPNetEvent.js';
|
|
30
|
+
import { AbiTypeToStr } from './TypeToStr.js';
|
|
30
31
|
|
|
31
32
|
const internal = Symbol.for('_btc_internal');
|
|
32
33
|
const bitcoinAbiCoder = new ABICoder();
|
|
@@ -286,9 +287,36 @@ export abstract class IBaseContract<T extends BaseContractProperties> implements
|
|
|
286
287
|
}
|
|
287
288
|
}
|
|
288
289
|
|
|
290
|
+
private getSelector(element: FunctionBaseData): string {
|
|
291
|
+
let name = element.name;
|
|
292
|
+
|
|
293
|
+
if (element.inputs && element.inputs.length) {
|
|
294
|
+
name += '(';
|
|
295
|
+
for (let i = 0; i < element.inputs.length; i++) {
|
|
296
|
+
const input = element.inputs[i];
|
|
297
|
+
const str = AbiTypeToStr[input.type];
|
|
298
|
+
|
|
299
|
+
if (!str) {
|
|
300
|
+
throw new Error(`Unsupported type: ${input.type}`);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (i > 0) {
|
|
304
|
+
name += ',';
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
name += str;
|
|
308
|
+
}
|
|
309
|
+
name += ')';
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return name;
|
|
313
|
+
}
|
|
314
|
+
|
|
289
315
|
private encodeFunctionData(element: FunctionBaseData, args: unknown[]): BinaryWriter {
|
|
290
316
|
const writer = new BinaryWriter();
|
|
291
|
-
|
|
317
|
+
|
|
318
|
+
const selectorStr = this.getSelector(element);
|
|
319
|
+
const selector = Number('0x' + bitcoinAbiCoder.encodeSelector(selectorStr));
|
|
292
320
|
writer.writeSelector(selector);
|
|
293
321
|
|
|
294
322
|
if (args.length !== (element.inputs?.length ?? 0)) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ABIDataTypes } from '@btc-vision/transaction';
|
|
2
|
+
|
|
3
|
+
export const AbiTypeToStr: { [key in ABIDataTypes]: string } = {
|
|
4
|
+
[ABIDataTypes.ADDRESS]: 'address',
|
|
5
|
+
[ABIDataTypes.BOOL]: 'bool',
|
|
6
|
+
[ABIDataTypes.BYTES]: 'bytes',
|
|
7
|
+
[ABIDataTypes.UINT256]: 'uint256',
|
|
8
|
+
[ABIDataTypes.UINT128]: 'uint128',
|
|
9
|
+
[ABIDataTypes.UINT64]: 'uint64',
|
|
10
|
+
[ABIDataTypes.UINT32]: 'uint32',
|
|
11
|
+
[ABIDataTypes.UINT16]: 'uint16',
|
|
12
|
+
[ABIDataTypes.UINT8]: 'uint8',
|
|
13
|
+
[ABIDataTypes.STRING]: 'string',
|
|
14
|
+
[ABIDataTypes.BYTES32]: 'bytes32',
|
|
15
|
+
[ABIDataTypes.ADDRESS_UINT256_TUPLE]: 'tuple(address,uint256)',
|
|
16
|
+
[ABIDataTypes.ARRAY_OF_ADDRESSES]: 'address[]',
|
|
17
|
+
[ABIDataTypes.ARRAY_OF_UINT256]: 'uint256[]',
|
|
18
|
+
[ABIDataTypes.ARRAY_OF_UINT128]: 'uint128[]',
|
|
19
|
+
[ABIDataTypes.ARRAY_OF_UINT64]: 'uint64[]',
|
|
20
|
+
[ABIDataTypes.ARRAY_OF_UINT32]: 'uint32[]',
|
|
21
|
+
[ABIDataTypes.ARRAY_OF_UINT16]: 'uint16[]',
|
|
22
|
+
[ABIDataTypes.ARRAY_OF_UINT8]: 'uint8[]',
|
|
23
|
+
[ABIDataTypes.ARRAY_OF_BYTES]: 'bytes[]',
|
|
24
|
+
[ABIDataTypes.ARRAY_OF_STRING]: 'string[]',
|
|
25
|
+
[ABIDataTypes.TUPLE]: 'tuple256',
|
|
26
|
+
};
|
package/src/opnet.ts
CHANGED
|
@@ -47,6 +47,7 @@ export * from './contracts/interfaces/ICallResult.js';
|
|
|
47
47
|
export * from './contracts/interfaces/IContract.js';
|
|
48
48
|
export * from './contracts/OPNetEvent.js';
|
|
49
49
|
export * from './contracts/interfaces/SimulatedTransaction.js';
|
|
50
|
+
export * from './contracts/TypeToStr.js';
|
|
50
51
|
|
|
51
52
|
/** Abi */
|
|
52
53
|
export * from './abi/BitcoinAbiTypes.js';
|
|
@@ -39,6 +39,11 @@ export abstract class TransactionBase<T extends OPNetTransactionTypes>
|
|
|
39
39
|
*/
|
|
40
40
|
public readonly burnedBitcoin: BigNumberish;
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* @description The priority fee of the transaction.
|
|
44
|
+
*/
|
|
45
|
+
public readonly priorityFee: BigNumberish;
|
|
46
|
+
|
|
42
47
|
/**
|
|
43
48
|
* @description The inputs of the transaction.
|
|
44
49
|
*/
|
|
@@ -80,6 +85,7 @@ export abstract class TransactionBase<T extends OPNetTransactionTypes>
|
|
|
80
85
|
this.index = transaction.index;
|
|
81
86
|
|
|
82
87
|
this.burnedBitcoin = BigInt(transaction.burnedBitcoin) || 0n;
|
|
88
|
+
this.priorityFee = BigInt(transaction.priorityFee) || 0n;
|
|
83
89
|
|
|
84
90
|
this.inputs = transaction.inputs.map((input) => new TransactionInput(input));
|
|
85
91
|
this.outputs = transaction.outputs.map(
|
|
@@ -34,6 +34,11 @@ export interface ITransactionBase<T extends OPNetTransactionTypes> extends ITran
|
|
|
34
34
|
*/
|
|
35
35
|
readonly burnedBitcoin: string | BigNumberish;
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* @description The priority fee of the transaction.
|
|
39
|
+
*/
|
|
40
|
+
readonly priorityFee: string | BigNumberish;
|
|
41
|
+
|
|
37
42
|
/**
|
|
38
43
|
* @description If the transaction was reverted, this field will contain the revert message.
|
|
39
44
|
*/
|