opnet 1.0.19 → 1.0.20

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.
Files changed (154) hide show
  1. package/build/_version.d.ts +1 -1
  2. package/build/_version.js +1 -1
  3. package/build/block/interfaces/BlockWitness.d.ts +11 -0
  4. package/build/block/interfaces/BlockWitness.js +1 -0
  5. package/build/contracts/Contract.d.ts +3 -1
  6. package/build/contracts/Contract.js +20 -12
  7. package/build/contracts/interfaces/IContract.d.ts +3 -1
  8. package/build/generator/WrappedGenerationParameters.d.ts +9 -0
  9. package/build/generator/WrappedGenerationParameters.js +14 -0
  10. package/build/opnet.d.ts +6 -1
  11. package/build/opnet.js +6 -1
  12. package/build/providers/AbstractRpcProvider.d.ts +8 -0
  13. package/build/providers/AbstractRpcProvider.js +63 -0
  14. package/build/providers/interfaces/Generate.d.ts +19 -0
  15. package/build/providers/interfaces/Generate.js +4 -0
  16. package/build/providers/interfaces/GenerateResult.d.ts +0 -0
  17. package/build/providers/interfaces/GenerateResult.js +1 -0
  18. package/build/providers/interfaces/ReorgInformation.d.ts +5 -0
  19. package/build/providers/interfaces/ReorgInformation.js +1 -0
  20. package/build/scripts/testMethods.js +12 -4
  21. package/build/transactions/TransactionReceipt.d.ts +3 -3
  22. package/build/transactions/TransactionReceipt.js +35 -16
  23. package/build/transactions/interfaces/BroadcastedTransaction.d.ts +7 -0
  24. package/build/transactions/interfaces/BroadcastedTransaction.js +1 -0
  25. package/build/transactions/interfaces/ITransaction.d.ts +2 -3
  26. package/build/transactions/interfaces/ITransactionReceipt.d.ts +9 -1
  27. package/cjs/_version.d.ts +1 -1
  28. package/cjs/_version.js +1 -1
  29. package/cjs/abi/BitcoinInterface.d.ts +1 -0
  30. package/cjs/abi/BitcoinInterface.js +16 -5
  31. package/cjs/abi/interfaces/BaseContractProperties.d.ts +2 -1
  32. package/cjs/abi/interfaces/BitcoinInterfaceAbi.d.ts +10 -5
  33. package/cjs/bitcoin/UTXOs.d.ts +1 -6
  34. package/cjs/bitcoin/interfaces/IUTXO.d.ts +7 -0
  35. package/cjs/bitcoin/interfaces/IUTXO.js +2 -0
  36. package/cjs/contracts/CallResult.d.ts +4 -2
  37. package/cjs/contracts/CallResult.js +3 -1
  38. package/cjs/contracts/Contract.d.ts +13 -3
  39. package/cjs/contracts/Contract.js +42 -15
  40. package/cjs/contracts/OPNetEvent.d.ts +15 -0
  41. package/cjs/contracts/OPNetEvent.js +22 -0
  42. package/cjs/contracts/interfaces/IContract.d.ts +3 -0
  43. package/cjs/opnet.d.ts +3 -0
  44. package/cjs/opnet.js +5 -1
  45. package/cjs/providers/AbstractRpcProvider.d.ts +2 -2
  46. package/cjs/scripts/ITestContract.d.ts +9 -0
  47. package/cjs/scripts/ITestContract.js +48 -0
  48. package/cjs/scripts/testContract.js +6 -23
  49. package/cjs/scripts/testMethods.js +16 -20
  50. package/cjs/transactions/DeploymentTransaction.d.ts +1 -0
  51. package/cjs/transactions/DeploymentTransaction.js +2 -0
  52. package/cjs/transactions/InteractionTransaction.d.ts +2 -4
  53. package/cjs/transactions/InteractionTransaction.js +4 -8
  54. package/cjs/transactions/Transaction.d.ts +2 -3
  55. package/cjs/transactions/Transaction.js +8 -5
  56. package/cjs/transactions/TransactionReceipt.d.ts +2 -1
  57. package/cjs/transactions/TransactionReceipt.js +24 -2
  58. package/cjs/transactions/interfaces/ITransaction.d.ts +9 -5
  59. package/cjs/transactions/interfaces/ITransactionReceipt.d.ts +8 -3
  60. package/docs/assets/highlight.css +7 -0
  61. package/docs/assets/navigation.js +1 -1
  62. package/docs/assets/search.js +1 -1
  63. package/docs/classes/AbstractRpcProvider.html +51 -14
  64. package/docs/classes/BaseContract.html +9 -8
  65. package/docs/classes/BitcoinAddress.html +2 -2
  66. package/docs/classes/BitcoinInterface.html +2 -2
  67. package/docs/classes/BitcoinUtils.html +2 -2
  68. package/docs/classes/Block.html +3 -3
  69. package/docs/classes/CallResult.html +2 -2
  70. package/docs/classes/ContractData.html +2 -2
  71. package/docs/classes/DeploymentTransaction.html +22 -22
  72. package/docs/classes/GenericTransaction.html +13 -13
  73. package/docs/classes/IBaseContract.html +8 -7
  74. package/docs/classes/InteractionTransaction.html +20 -20
  75. package/docs/classes/JSONRpcProvider.html +50 -13
  76. package/docs/classes/OPNetEvent.html +2 -2
  77. package/docs/classes/StoredValue.html +2 -2
  78. package/docs/classes/TransactionBase.html +13 -13
  79. package/docs/classes/TransactionInput.html +2 -2
  80. package/docs/classes/TransactionOutput.html +2 -2
  81. package/docs/classes/TransactionParser.html +2 -2
  82. package/docs/classes/TransactionReceipt.html +10 -9
  83. package/docs/classes/UTXO.html +2 -2
  84. package/docs/classes/WebSocketRpcProvider.html +50 -13
  85. package/docs/classes/WrappedGeneration.html +185 -0
  86. package/docs/enums/BitcoinAbiTypes.html +2 -2
  87. package/docs/enums/GenerateTarget.html +175 -0
  88. package/docs/enums/OPNetTransactionTypes.html +2 -2
  89. package/docs/functions/getContract.html +1 -1
  90. package/docs/hierarchy.html +1 -1
  91. package/docs/interfaces/BaseContractProperties.html +4 -3
  92. package/docs/interfaces/BitcoinAbiValue.html +3 -3
  93. package/docs/interfaces/BitcoinInterfaceAbiBase.html +2 -2
  94. package/docs/interfaces/BroadcastedTransaction.html +184 -0
  95. package/docs/interfaces/ContractEvents.html +174 -0
  96. package/docs/interfaces/EventBaseData.html +2 -2
  97. package/docs/interfaces/FunctionBaseData.html +2 -2
  98. package/docs/interfaces/GenerationConstraints.html +186 -0
  99. package/docs/interfaces/IAccessList.html +1 -1
  100. package/docs/interfaces/IAccessListItem.html +1 -1
  101. package/docs/interfaces/IBlock.html +3 -3
  102. package/docs/interfaces/IBlockCommon.html +3 -3
  103. package/docs/interfaces/IBlockWitness.html +176 -0
  104. package/docs/interfaces/IBlockWitnessAPI.html +178 -0
  105. package/docs/interfaces/ICallRequestError.html +2 -2
  106. package/docs/interfaces/ICallResultData.html +2 -2
  107. package/docs/interfaces/ICommonTransaction.html +15 -15
  108. package/docs/interfaces/IContract.html +4 -3
  109. package/docs/interfaces/IDecodedEvent.html +2 -2
  110. package/docs/interfaces/IDeploymentTransaction.html +21 -21
  111. package/docs/interfaces/IGenericTransaction.html +12 -12
  112. package/docs/interfaces/IInteractionTransaction.html +19 -19
  113. package/docs/interfaces/IRawContract.html +2 -2
  114. package/docs/interfaces/IRawContractEvents.html +174 -0
  115. package/docs/interfaces/IStorageValue.html +2 -2
  116. package/docs/interfaces/ITransactionBase.html +12 -12
  117. package/docs/interfaces/ITransactionInput.html +2 -2
  118. package/docs/interfaces/ITransactionOutput.html +2 -2
  119. package/docs/interfaces/ITransactionReceipt.html +6 -6
  120. package/docs/interfaces/IUTXO.html +2 -2
  121. package/docs/interfaces/NetEventDocument.html +7 -2
  122. package/docs/interfaces/ReorgInformation.html +177 -0
  123. package/docs/interfaces/WrappedGenerationParameters.html +184 -0
  124. package/docs/modules.html +13 -0
  125. package/docs/types/BaseContractProperty.html +1 -1
  126. package/docs/types/BitcoinAddressLike.html +1 -1
  127. package/docs/types/BitcoinInterfaceAbi.html +1 -1
  128. package/docs/types/BlockHeaderChecksumProof.html +1 -1
  129. package/docs/types/BlockWitnesses.html +174 -0
  130. package/docs/types/ContractDecodedObjectResult.html +1 -1
  131. package/docs/types/DecodedCallResult.html +1 -1
  132. package/docs/types/DecodedOutput.html +1 -1
  133. package/docs/types/GenerationParameters.html +174 -0
  134. package/docs/types/ICallResult.html +1 -1
  135. package/docs/types/ITransaction.html +1 -1
  136. package/docs/types/PointerLike.html +1 -1
  137. package/docs/types/RawContractEvents.html +174 -0
  138. package/docs/types/UTXOs.html +1 -1
  139. package/docs/variables/version.html +1 -1
  140. package/package.json +9 -8
  141. package/src/_version.ts +1 -1
  142. package/src/block/interfaces/BlockWitness.ts +14 -0
  143. package/src/contracts/Contract.ts +32 -24
  144. package/src/contracts/interfaces/IContract.ts +4 -1
  145. package/src/generator/WrappedGenerationParameters.ts +28 -0
  146. package/src/opnet.ts +10 -1
  147. package/src/providers/AbstractRpcProvider.ts +128 -0
  148. package/src/providers/interfaces/Generate.ts +42 -0
  149. package/src/providers/interfaces/ReorgInformation.ts +6 -0
  150. package/src/scripts/testMethods.ts +46 -29
  151. package/src/transactions/TransactionReceipt.ts +46 -18
  152. package/src/transactions/interfaces/BroadcastedTransaction.ts +24 -0
  153. package/src/transactions/interfaces/ITransaction.ts +2 -3
  154. package/src/transactions/interfaces/ITransactionReceipt.ts +19 -1
@@ -1 +1 @@
1
- export declare const version = "1.0.18";
1
+ export declare const version = "1.0.20";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.0.18';
1
+ export const version = '1.0.20';
@@ -0,0 +1,11 @@
1
+ export interface IBlockWitnessAPI {
2
+ readonly trusted: boolean;
3
+ readonly signature: string;
4
+ readonly identity?: string;
5
+ readonly opnetPubKey?: string;
6
+ }
7
+ export interface IBlockWitness {
8
+ blockNumber: bigint | string;
9
+ readonly witnesses: IBlockWitnessAPI[];
10
+ }
11
+ export type BlockWitnesses = IBlockWitness[];
@@ -0,0 +1 @@
1
+ export {};
@@ -5,6 +5,7 @@ import { BaseContractProperties } from '../abi/interfaces/BaseContractProperties
5
5
  import { BitcoinInterfaceAbi } from '../abi/interfaces/BitcoinInterfaceAbi.js';
6
6
  import { BitcoinAddressLike, DecodedCallResult } from '../common/CommonTypes.js';
7
7
  import { AbstractRpcProvider } from '../providers/AbstractRpcProvider.js';
8
+ import { ContractEvents } from '../transactions/interfaces/ITransactionReceipt.js';
8
9
  import { IContract } from './interfaces/IContract.js';
9
10
  import { OPNetEvent } from './OPNetEvent.js';
10
11
  declare const internal: unique symbol;
@@ -22,7 +23,8 @@ export declare abstract class IBaseContract<T extends BaseContractProperties> im
22
23
  readonly [internal]: keyof T | undefined;
23
24
  private events;
24
25
  protected constructor(address: BitcoinAddressLike, abi: BitcoinInterface | BitcoinInterfaceAbi, provider: AbstractRpcProvider);
25
- decodeEvents(events: NetEvent[]): OPNetEvent[];
26
+ decodeEvents(events: NetEvent[] | ContractEvents): OPNetEvent[];
27
+ decodeEvent(event: NetEvent): OPNetEvent;
26
28
  protected getFunction(name: symbol): BaseContractProperty | undefined | string | number | symbol;
27
29
  private defineInternalFunctions;
28
30
  private encodeFunctionData;
@@ -19,21 +19,28 @@ export class IBaseContract {
19
19
  }
20
20
  decodeEvents(events) {
21
21
  const decodedEvents = [];
22
- for (let event of events) {
23
- const eventData = this.events.get(event.eventType);
24
- if (!eventData || eventData.values.length === 0) {
25
- const decodedEvent = new OPNetEvent(event.eventType, event.eventDataSelector, event.eventData);
26
- decodedEvents.push(decodedEvent);
27
- continue;
22
+ if (!Array.isArray(events)) {
23
+ events = events[this.address.toString()];
24
+ if (!events) {
25
+ return [];
28
26
  }
29
- const binaryReader = new BinaryReader(event.eventData);
30
- const out = this.decodeOutput(eventData.values, binaryReader);
31
- const decodedEvent = new OPNetEvent(event.eventType, event.eventDataSelector, event.eventData);
32
- decodedEvent.setDecoded(out);
33
- decodedEvents.push(decodedEvent);
27
+ }
28
+ for (let event of events) {
29
+ decodedEvents.push(this.decodeEvent(event));
34
30
  }
35
31
  return decodedEvents;
36
32
  }
33
+ decodeEvent(event) {
34
+ const eventData = this.events.get(event.eventType);
35
+ if (!eventData || eventData.values.length === 0) {
36
+ return new OPNetEvent(event.eventType, event.eventDataSelector, event.eventData);
37
+ }
38
+ const binaryReader = new BinaryReader(event.eventData);
39
+ const out = this.decodeOutput(eventData.values, binaryReader);
40
+ const decodedEvent = new OPNetEvent(event.eventType, event.eventDataSelector, event.eventData);
41
+ decodedEvent.setDecoded(out);
42
+ return decodedEvent;
43
+ }
37
44
  getFunction(name) {
38
45
  const key = name;
39
46
  return this[key];
@@ -178,7 +185,8 @@ export class IBaseContract {
178
185
  callFunction(element) {
179
186
  return async (...args) => {
180
187
  const data = this.encodeFunctionData(element, args);
181
- const response = await this.provider.call(this.address, Buffer.from(data.getBuffer()));
188
+ const buffer = Buffer.from(data.getBuffer());
189
+ const response = await this.provider.call(this.address, buffer);
182
190
  if ('error' in response) {
183
191
  return response;
184
192
  }
@@ -1,7 +1,9 @@
1
1
  import { NetEvent } from '@btc-vision/bsi-binary';
2
2
  import { BitcoinAddressLike } from '../../common/CommonTypes.js';
3
+ import { ContractEvents } from '../../transactions/interfaces/ITransactionReceipt.js';
3
4
  import { OPNetEvent } from '../OPNetEvent.js';
4
5
  export interface IContract {
5
6
  readonly address: BitcoinAddressLike;
6
- decodeEvents(events: NetEvent[]): OPNetEvent[];
7
+ decodeEvents(events: NetEvent[] | ContractEvents): OPNetEvent[];
8
+ decodeEvent(event: NetEvent): OPNetEvent;
7
9
  }
@@ -0,0 +1,9 @@
1
+ import { GenerationConstraints, WrappedGenerationParameters } from '../providers/interfaces/Generate.js';
2
+ export declare class WrappedGeneration implements WrappedGenerationParameters {
3
+ readonly constraints: GenerationConstraints;
4
+ readonly entities: string[];
5
+ readonly keys: string[];
6
+ readonly signature: string;
7
+ readonly vault: string;
8
+ constructor(params: WrappedGenerationParameters);
9
+ }
@@ -0,0 +1,14 @@
1
+ export class WrappedGeneration {
2
+ constraints;
3
+ entities;
4
+ keys;
5
+ signature;
6
+ vault;
7
+ constructor(params) {
8
+ this.constraints = params.constraints;
9
+ this.entities = params.entities;
10
+ this.keys = params.keys;
11
+ this.signature = params.signature;
12
+ this.vault = params.vault;
13
+ }
14
+ }
package/build/opnet.d.ts CHANGED
@@ -9,7 +9,11 @@ export * from './transactions/TransactionOutput.js';
9
9
  export * from './providers/JSONRpcProvider.js';
10
10
  export * from './providers/AbstractRpcProvider.js';
11
11
  export * from './providers/WebsocketRpcProvider.js';
12
+ export * from './providers/interfaces/Generate.js';
13
+ export * from './providers/interfaces/ReorgInformation.js';
12
14
  export * from './block/Block.js';
15
+ export * from './block/interfaces/IBlock.js';
16
+ export * from './block/interfaces/BlockWitness.js';
13
17
  export * from './transactions/TransactionParser.js';
14
18
  export * from './contracts/ContractData.js';
15
19
  export * from './contracts/CallResult.js';
@@ -25,13 +29,14 @@ export * from './abi/BitcoinAbiTypes.js';
25
29
  export * from './abi/interfaces/BaseContractProperties.js';
26
30
  export * from './abi/BaseContractProperty.js';
27
31
  export * from './utils/BitcoinUtils.js';
32
+ export * from './generator/WrappedGenerationParameters.js';
28
33
  export * from './storage/StoredValue.js';
29
34
  export * from './storage/interfaces/IStorageValue.js';
30
- export * from './block/interfaces/IBlock.js';
31
35
  export * from './transactions/interfaces/ITransaction.js';
32
36
  export * from './transactions/interfaces/ITransactionReceipt.js';
33
37
  export * from './transactions/TransactionReceipt.js';
34
38
  export * from './contracts/interfaces/IRawContract.js';
39
+ export * from './transactions/interfaces/BroadcastedTransaction.js';
35
40
  export * from './common/CommonTypes.js';
36
41
  export * from './bitcoin/BitcoinAddress.js';
37
42
  export * from './bitcoin/UTXOs.js';
package/build/opnet.js CHANGED
@@ -9,7 +9,11 @@ export * from './transactions/TransactionOutput.js';
9
9
  export * from './providers/JSONRpcProvider.js';
10
10
  export * from './providers/AbstractRpcProvider.js';
11
11
  export * from './providers/WebsocketRpcProvider.js';
12
+ export * from './providers/interfaces/Generate.js';
13
+ export * from './providers/interfaces/ReorgInformation.js';
12
14
  export * from './block/Block.js';
15
+ export * from './block/interfaces/IBlock.js';
16
+ export * from './block/interfaces/BlockWitness.js';
13
17
  export * from './transactions/TransactionParser.js';
14
18
  export * from './contracts/ContractData.js';
15
19
  export * from './contracts/CallResult.js';
@@ -25,13 +29,14 @@ export * from './abi/BitcoinAbiTypes.js';
25
29
  export * from './abi/interfaces/BaseContractProperties.js';
26
30
  export * from './abi/BaseContractProperty.js';
27
31
  export * from './utils/BitcoinUtils.js';
32
+ export * from './generator/WrappedGenerationParameters.js';
28
33
  export * from './storage/StoredValue.js';
29
34
  export * from './storage/interfaces/IStorageValue.js';
30
- export * from './block/interfaces/IBlock.js';
31
35
  export * from './transactions/interfaces/ITransaction.js';
32
36
  export * from './transactions/interfaces/ITransactionReceipt.js';
33
37
  export * from './transactions/TransactionReceipt.js';
34
38
  export * from './contracts/interfaces/IRawContract.js';
39
+ export * from './transactions/interfaces/BroadcastedTransaction.js';
35
40
  export * from './common/CommonTypes.js';
36
41
  export * from './bitcoin/BitcoinAddress.js';
37
42
  export * from './bitcoin/UTXOs.js';
@@ -3,14 +3,18 @@ import '../serialize/BigInt.js';
3
3
  import { Network } from 'bitcoinjs-lib';
4
4
  import { BigNumberish, BlockTag, JsonRpcApiProvider } from 'ethers';
5
5
  import { Block } from '../block/Block.js';
6
+ import { BlockWitnesses } from '../block/interfaces/BlockWitness.js';
6
7
  import { BitcoinAddressLike } from '../common/CommonTypes.js';
7
8
  import { CallResult } from '../contracts/CallResult.js';
8
9
  import { ContractData } from '../contracts/ContractData.js';
9
10
  import { ICallRequestError } from '../contracts/interfaces/ICallResult.js';
11
+ import { WrappedGeneration } from '../generator/WrappedGenerationParameters.js';
10
12
  import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
11
13
  import { StoredValue } from '../storage/StoredValue.js';
14
+ import { BroadcastedTransaction } from '../transactions/interfaces/BroadcastedTransaction.js';
12
15
  import { TransactionBase } from '../transactions/Transaction.js';
13
16
  import { TransactionReceipt } from '../transactions/TransactionReceipt.js';
17
+ import { ReorgInformation } from './interfaces/ReorgInformation.js';
14
18
  export declare abstract class AbstractRpcProvider {
15
19
  protected abstract readonly provider: JsonRpcApiProvider;
16
20
  private nextId;
@@ -26,6 +30,10 @@ export declare abstract class AbstractRpcProvider {
26
30
  getCode(address: BitcoinAddressLike, onlyBytecode?: boolean): Promise<ContractData | Buffer>;
27
31
  getStorageAt(address: BitcoinAddressLike, rawPointer: bigint | string, proofs?: boolean, height?: BigNumberish): Promise<StoredValue>;
28
32
  call(to: BitcoinAddressLike, data: Buffer | string, from?: BitcoinAddressLike, height?: BigNumberish): Promise<CallResult | ICallRequestError>;
33
+ sendRawTransaction(tx: string, psbt: boolean): Promise<BroadcastedTransaction>;
34
+ getBlockWitness(height?: BigNumberish | -1, trusted?: boolean, limit?: number, page?: number): Promise<BlockWitnesses>;
35
+ getReorg(fromBlock?: BigNumberish, toBlock?: BigNumberish): Promise<ReorgInformation[]>;
36
+ requestTrustedPublicKeyForBitcoinWrapping(amount: BigNumberish): Promise<WrappedGeneration>;
29
37
  protected abstract providerUrl(url: string): string;
30
38
  private bufferToHex;
31
39
  private bigintToBase64;
@@ -5,9 +5,11 @@ import { UTXO } from '../bitcoin/UTXOs.js';
5
5
  import { Block } from '../block/Block.js';
6
6
  import { CallResult } from '../contracts/CallResult.js';
7
7
  import { ContractData } from '../contracts/ContractData.js';
8
+ import { WrappedGeneration } from '../generator/WrappedGenerationParameters.js';
8
9
  import { StoredValue } from '../storage/StoredValue.js';
9
10
  import { TransactionParser } from '../transactions/TransactionParser.js';
10
11
  import { TransactionReceipt } from '../transactions/TransactionReceipt.js';
12
+ import { GenerateTarget } from './interfaces/Generate.js';
11
13
  export class AbstractRpcProvider {
12
14
  nextId = 0;
13
15
  constructor() { }
@@ -126,6 +128,67 @@ export class AbstractRpcProvider {
126
128
  }
127
129
  return new CallResult(result);
128
130
  }
131
+ async sendRawTransaction(tx, psbt) {
132
+ if (!/^[0-9A-Fa-f]+$/.test(tx)) {
133
+ throw new Error('Invalid hex string');
134
+ }
135
+ const payload = this.buildJsonRpcPayload('btc_sendRawTransaction', [
136
+ tx,
137
+ psbt,
138
+ ]);
139
+ const rawTx = await this.callPayloadSingle(payload);
140
+ const result = rawTx.result;
141
+ if (result && result.identifier) {
142
+ return {
143
+ ...result,
144
+ identifier: BigInt(result.identifier),
145
+ };
146
+ }
147
+ return result;
148
+ }
149
+ async getBlockWitness(height = -1, trusted, limit, page) {
150
+ const params = [height.toString()];
151
+ if (trusted !== undefined && trusted !== null)
152
+ params.push(trusted);
153
+ if (limit !== undefined && limit !== null)
154
+ params.push(limit);
155
+ if (page !== undefined && page !== null)
156
+ params.push(page);
157
+ const payload = this.buildJsonRpcPayload('btc_blockWitness', params);
158
+ const rawWitnesses = await this.callPayloadSingle(payload);
159
+ const result = rawWitnesses.result;
160
+ for (let i = 0; i < result.length; i++) {
161
+ result[i].blockNumber = BigInt('0x' + result[i].blockNumber);
162
+ }
163
+ return result;
164
+ }
165
+ async getReorg(fromBlock, toBlock) {
166
+ const params = [];
167
+ if (fromBlock !== undefined && fromBlock !== null)
168
+ params.push(fromBlock.toString());
169
+ if (toBlock !== undefined && toBlock !== null)
170
+ params.push(toBlock.toString());
171
+ const payload = this.buildJsonRpcPayload('btc_reorg', params);
172
+ const rawReorg = await this.callPayloadSingle(payload);
173
+ const result = rawReorg.result;
174
+ if (result.length > 0) {
175
+ for (let i = 0; i < result.length; i++) {
176
+ const res = result[i];
177
+ res.fromBlock = BigInt('0x' + res.fromBlock);
178
+ res.toBlock = BigInt('0x' + res.toBlock);
179
+ }
180
+ }
181
+ return result;
182
+ }
183
+ async requestTrustedPublicKeyForBitcoinWrapping(amount) {
184
+ const payload = this.buildJsonRpcPayload('btc_generate', [
185
+ GenerateTarget.WRAP,
186
+ amount.toString(),
187
+ ]);
188
+ const rawPublicKey = await this.callPayloadSingle(payload);
189
+ const result = rawPublicKey.result;
190
+ return new WrappedGeneration(result);
191
+ }
129
192
  bufferToHex(buffer) {
130
193
  return buffer.toString('hex');
131
194
  }
@@ -0,0 +1,19 @@
1
+ export declare enum GenerateTarget {
2
+ WRAP = 0
3
+ }
4
+ export interface GenerationConstraints {
5
+ readonly timestamp: number;
6
+ readonly version: string;
7
+ readonly minimum: number;
8
+ readonly transactionMinimum: number;
9
+ readonly minimumValidatorTransactionGeneration: number;
10
+ readonly maximumValidatorPerTrustedEntities: number;
11
+ }
12
+ export interface WrappedGenerationParameters {
13
+ readonly keys: string[];
14
+ readonly vault: string;
15
+ readonly entities: string[];
16
+ readonly signature: string;
17
+ readonly constraints: GenerationConstraints;
18
+ }
19
+ export type GenerationParameters = WrappedGenerationParameters;
@@ -0,0 +1,4 @@
1
+ export var GenerateTarget;
2
+ (function (GenerateTarget) {
3
+ GenerateTarget[GenerateTarget["WRAP"] = 0] = "WRAP";
4
+ })(GenerateTarget || (GenerateTarget = {}));
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,5 @@
1
+ export interface ReorgInformation {
2
+ fromBlock: string | bigint;
3
+ toBlock: string | bigint;
4
+ readonly timestamp: number;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -3,8 +3,8 @@ import { JSONRpcProvider } from '../providers/JSONRpcProvider.js';
3
3
  import { TestContractABI } from './ITestContract.js';
4
4
  const provider = new JSONRpcProvider('http://localhost:9001');
5
5
  (async () => {
6
- const transaction = await provider.getTransaction('af7a6001150b2b4ec7361515d3e5075c81d9f975c8ec22989db0a0c474c08418');
7
- console.log('Transaction:', transaction);
6
+ const transaction = (await provider.getTransaction('af7a6001150b2b4ec7361515d3e5075c81d9f975c8ec22989db0a0c474c08418'));
7
+ console.log('Transaction:', transaction, transaction.calldata.toString('hex'));
8
8
  const receipt = await provider.getTransactionReceipt('af7a6001150b2b4ec7361515d3e5075c81d9f975c8ec22989db0a0c474c08418');
9
9
  console.log('Receipt:', receipt);
10
10
  const contract = getContract('bcrt1pyrs3eqwnrmd4ql3nwvx66yzp0wc24xd2t9pf8699ln340pjs7f3sar3tum', TestContractABI, provider);
@@ -13,8 +13,16 @@ const provider = new JSONRpcProvider('http://localhost:9001');
13
13
  console.log('No events');
14
14
  }
15
15
  else {
16
- console.log('Events:', events);
16
+ console.log('Decoded Events:', receipt, events);
17
17
  const decodedEvents = contract.decodeEvents(events);
18
- console.log('Decoded events:', decodedEvents);
18
+ console.log('Decoded Events:', decodedEvents);
19
19
  }
20
+ const callResult = await provider.call('bcrt1pyrs3eqwnrmd4ql3nwvx66yzp0wc24xd2t9pf8699ln340pjs7f3sar3tum', 'ed1470ec6263317065653831396563313361383462353830633934343431383966386237313131653466663335666263656336626534386638346237396137626362356300000000000000008146a1bb27e3b07c40f0209b9f876f80ad503ff71b893e44');
21
+ console.log('Call result:', callResult);
22
+ const blockWitness = await provider.getBlockWitness(398);
23
+ console.dir(blockWitness, { depth: 10, colors: true });
24
+ const reorgs = await provider.getReorg();
25
+ console.log('Reorgs:', reorgs);
26
+ const wrapParams = await provider.requestTrustedPublicKeyForBitcoinWrapping(1000n);
27
+ console.log('Wrap Params:', wrapParams);
20
28
  })();
@@ -1,11 +1,11 @@
1
1
  /// <reference types="node" />
2
- import { NetEvent } from '@btc-vision/bsi-binary';
3
- import { ITransactionReceipt } from './interfaces/ITransactionReceipt.js';
2
+ import { ContractEvents, ITransactionReceipt } from './interfaces/ITransactionReceipt.js';
4
3
  export declare class TransactionReceipt implements ITransactionReceipt {
5
4
  readonly receipt?: Buffer;
6
5
  readonly receiptProofs: string[];
7
- readonly events: NetEvent[];
6
+ readonly events: ContractEvents;
8
7
  readonly revert?: Buffer;
9
8
  constructor(receipt: ITransactionReceipt);
10
9
  private parseEvents;
10
+ private decodeEvent;
11
11
  }
@@ -9,26 +9,45 @@ export class TransactionReceipt {
9
9
  ? Buffer.from(receipt.receipt, 'base64')
10
10
  : undefined;
11
11
  this.receiptProofs = receipt.receiptProofs || [];
12
- this.events = receipt.events ? this.parseEvents(receipt.events) : [];
12
+ this.events = receipt.events ? this.parseEvents(receipt.events) : {};
13
13
  this.revert = receipt.revert ? Buffer.from(receipt.revert, 'base64') : undefined;
14
14
  }
15
15
  parseEvents(events) {
16
- return events.map((event) => {
17
- let eventData;
18
- let eventDataSelector;
19
- if (typeof event.eventData === 'string') {
20
- eventData = new Uint8Array(Buffer.from(event.eventData, 'base64'));
16
+ const parsedEvents = {};
17
+ if (!Array.isArray(events)) {
18
+ for (const [key, value] of Object.entries(events)) {
19
+ parsedEvents[key] = value.map((event) => {
20
+ return this.decodeEvent(event);
21
+ });
21
22
  }
22
- else {
23
- eventData = event.eventData;
23
+ }
24
+ else {
25
+ for (const event of events) {
26
+ const parsedEvent = this.decodeEvent(event);
27
+ const contractAddress = event.contractAddress;
28
+ if (!parsedEvents[contractAddress]) {
29
+ parsedEvents[contractAddress] = [];
30
+ }
31
+ parsedEvents[contractAddress].push(parsedEvent);
24
32
  }
25
- if (typeof event.eventDataSelector === 'string') {
26
- eventDataSelector = BigInt(event.eventDataSelector);
27
- }
28
- else {
29
- eventDataSelector = event.eventDataSelector;
30
- }
31
- return new NetEvent(event.eventType, eventDataSelector, eventData);
32
- });
33
+ }
34
+ return parsedEvents;
35
+ }
36
+ decodeEvent(event) {
37
+ let eventData;
38
+ let eventDataSelector;
39
+ if (typeof event.eventData === 'string') {
40
+ eventData = new Uint8Array(Buffer.from(event.eventData, 'base64'));
41
+ }
42
+ else {
43
+ eventData = event.eventData;
44
+ }
45
+ if (typeof event.eventDataSelector === 'string') {
46
+ eventDataSelector = BigInt(event.eventDataSelector);
47
+ }
48
+ else {
49
+ eventDataSelector = event.eventDataSelector;
50
+ }
51
+ return new NetEvent(event.eventType, eventDataSelector, eventData);
33
52
  }
34
53
  }
@@ -0,0 +1,7 @@
1
+ export interface BroadcastedTransaction {
2
+ readonly success: boolean;
3
+ readonly result?: string;
4
+ readonly error?: string;
5
+ readonly peers?: number;
6
+ readonly identifier: bigint | string;
7
+ }
@@ -1,10 +1,9 @@
1
1
  /// <reference types="node" />
2
- import { NetEvent } from '@btc-vision/bsi-binary';
3
2
  import { BigNumberish } from 'ethers';
4
3
  import { OPNetTransactionTypes } from '../../interfaces/opnet/OPNetTransactionTypes.js';
5
4
  import { ITransactionInput, TransactionInput } from '../TransactionInput.js';
6
5
  import { ITransactionOutput, TransactionOutput } from '../TransactionOutput.js';
7
- import { ITransactionReceipt } from './ITransactionReceipt.js';
6
+ import { ContractEvents, ITransactionReceipt } from './ITransactionReceipt.js';
8
7
  export interface ITransactionBase<T extends OPNetTransactionTypes> extends ITransactionReceipt {
9
8
  readonly id: string;
10
9
  readonly hash: string;
@@ -36,7 +35,7 @@ export interface IInteractionTransaction extends ICommonTransaction<OPNetTransac
36
35
  readonly contractSecret: string | Buffer;
37
36
  readonly interactionPubKey: string | Buffer;
38
37
  readonly from: string;
39
- readonly events: NetEvent[];
38
+ readonly events: ContractEvents;
40
39
  readonly receipt?: string | Buffer;
41
40
  readonly receiptProofs?: string[];
42
41
  }
@@ -1,13 +1,21 @@
1
1
  /// <reference types="node" />
2
2
  import { NetEvent } from '@btc-vision/bsi-binary';
3
3
  export interface NetEventDocument {
4
+ readonly contractAddress: string;
4
5
  readonly eventType: string;
5
6
  readonly eventDataSelector: string;
6
7
  readonly eventData: string;
7
8
  }
9
+ export interface IRawContractEvents {
10
+ [key: string]: NetEventDocument[];
11
+ }
12
+ export type RawContractEvents = IRawContractEvents | NetEventDocument[];
13
+ export interface ContractEvents {
14
+ [key: string]: NetEvent[];
15
+ }
8
16
  export interface ITransactionReceipt {
9
17
  readonly receipt?: string | Buffer;
10
18
  readonly receiptProofs?: string[];
11
- readonly events?: NetEventDocument[] | NetEvent[];
19
+ readonly events?: RawContractEvents | ContractEvents;
12
20
  readonly revert?: string | Buffer;
13
21
  }
package/cjs/_version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "1.0.12";
1
+ export declare const version = "1.0.19";
package/cjs/_version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
- exports.version = '1.0.12';
4
+ exports.version = '1.0.19';
@@ -4,6 +4,7 @@ export declare class BitcoinInterface {
4
4
  constructor(abi: BitcoinInterfaceAbi);
5
5
  static from(abi: BitcoinInterface | BitcoinInterfaceAbi): BitcoinInterface;
6
6
  hasFunction(name: string): boolean;
7
+ hasEvent(name: string): boolean;
7
8
  private verifyAbi;
8
9
  private verifyAbiValues;
9
10
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BitcoinInterface = void 0;
4
+ const BitcoinAbiTypes_js_1 = require("./BitcoinAbiTypes.js");
4
5
  class BitcoinInterface {
5
6
  abi;
6
7
  constructor(abi) {
@@ -14,7 +15,10 @@ class BitcoinInterface {
14
15
  return new BitcoinInterface(abi);
15
16
  }
16
17
  hasFunction(name) {
17
- return this.abi.some((element) => element.name === name && element.type === 'function');
18
+ return this.abi.some((element) => element.name === name && element.type === BitcoinAbiTypes_js_1.BitcoinAbiTypes.Function);
19
+ }
20
+ hasEvent(name) {
21
+ return this.abi.some((element) => element.name === name && element.type === BitcoinAbiTypes_js_1.BitcoinAbiTypes.Event);
18
22
  }
19
23
  verifyAbi(abi) {
20
24
  if (abi.length === 0) {
@@ -28,10 +32,17 @@ class BitcoinInterface {
28
32
  if (!element.type) {
29
33
  throw new Error('The ABI provided is missing a type.');
30
34
  }
31
- if (element.inputs && element.inputs.length)
32
- this.verifyAbiValues(element.inputs);
33
- if (element.outputs && element.outputs.length)
34
- this.verifyAbiValues(element.outputs);
35
+ if (element.type === BitcoinAbiTypes_js_1.BitcoinAbiTypes.Function) {
36
+ if (element.inputs && element.inputs.length)
37
+ this.verifyAbiValues(element.inputs);
38
+ if (element.outputs && element.outputs.length) {
39
+ this.verifyAbiValues(element.outputs);
40
+ }
41
+ }
42
+ else if (element.type === BitcoinAbiTypes_js_1.BitcoinAbiTypes.Event) {
43
+ if (element.values && element.values.length)
44
+ this.verifyAbiValues(element.values);
45
+ }
35
46
  }
36
47
  }
37
48
  verifyAbiValues(inputs) {
@@ -1,4 +1,5 @@
1
+ import { IContract } from '../../contracts/interfaces/IContract.js';
1
2
  import { BaseContractProperty } from '../BaseContractProperty.js';
2
- export interface BaseContractProperties {
3
+ export interface BaseContractProperties extends IContract {
3
4
  [key: symbol]: BaseContractProperty;
4
5
  }
@@ -1,11 +1,16 @@
1
1
  import { BitcoinAbiTypes } from '../BitcoinAbiTypes.js';
2
2
  import { BitcoinAbiValue } from './BitcoinAbiValue.js';
3
- export interface BitcoinInterfaceAbiBase {
4
- readonly constant?: boolean;
3
+ export interface BitcoinInterfaceAbiBase<T extends BitcoinAbiTypes> {
5
4
  readonly name: string;
5
+ readonly type: T;
6
+ }
7
+ export interface FunctionBaseData extends BitcoinInterfaceAbiBase<BitcoinAbiTypes.Function> {
8
+ readonly constant?: boolean;
9
+ readonly payable?: boolean;
6
10
  readonly inputs?: BitcoinAbiValue[];
7
11
  readonly outputs?: BitcoinAbiValue[];
8
- readonly type: BitcoinAbiTypes;
9
- readonly payable?: boolean;
10
12
  }
11
- export type BitcoinInterfaceAbi = BitcoinInterfaceAbiBase[];
13
+ export interface EventBaseData extends BitcoinInterfaceAbiBase<BitcoinAbiTypes.Event> {
14
+ readonly values: BitcoinAbiValue[];
15
+ }
16
+ export type BitcoinInterfaceAbi = (FunctionBaseData | EventBaseData)[];
@@ -1,10 +1,5 @@
1
1
  import { ScriptPubKey } from '@btc-vision/bsi-bitcoin-rpc';
2
- export interface IUTXO {
3
- readonly transactionId: string;
4
- readonly outputIndex: number;
5
- readonly value: bigint | string;
6
- readonly scriptPubKey: ScriptPubKey;
7
- }
2
+ import { IUTXO } from './interfaces/IUTXO.js';
8
3
  export declare class UTXO implements IUTXO {
9
4
  readonly transactionId: string;
10
5
  readonly outputIndex: number;
@@ -0,0 +1,7 @@
1
+ import { ScriptPubKey } from '@btc-vision/bsi-bitcoin-rpc';
2
+ export interface IUTXO {
3
+ readonly transactionId: string;
4
+ readonly outputIndex: number;
5
+ readonly value: bigint | string;
6
+ readonly scriptPubKey: ScriptPubKey;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });