opnet 1.0.16 → 1.0.17

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.
@@ -1,5 +1,6 @@
1
1
  import { BinaryReader, NetEvent } from '@btc-vision/bsi-binary';
2
2
  import { DecodedCallResult } from '../common/CommonTypes.js';
3
+ import { ContractDecodedObjectResult, DecodedOutput } from './Contract.js';
3
4
  import { IAccessList } from './interfaces/IAccessList.js';
4
5
  import { ICallResultData } from './interfaces/ICallResult.js';
5
6
  export declare class CallResult implements ICallResultData {
@@ -7,7 +8,8 @@ export declare class CallResult implements ICallResultData {
7
8
  readonly events: NetEvent[];
8
9
  readonly accessList: IAccessList;
9
10
  readonly decoded: Array<DecodedCallResult>;
11
+ properties: ContractDecodedObjectResult;
10
12
  constructor(iCallResult: ICallResultData);
11
- setDecoded(decoded: Array<DecodedCallResult>): void;
13
+ setDecoded(decoded: DecodedOutput): void;
12
14
  private base64ToUint8Array;
13
15
  }
@@ -4,6 +4,7 @@ export class CallResult {
4
4
  events;
5
5
  accessList;
6
6
  decoded = [];
7
+ properties = {};
7
8
  constructor(iCallResult) {
8
9
  this.events = iCallResult.events;
9
10
  this.accessList = iCallResult.accessList;
@@ -13,7 +14,8 @@ export class CallResult {
13
14
  : iCallResult.result;
14
15
  }
15
16
  setDecoded(decoded) {
16
- this.decoded.push(...decoded);
17
+ this.properties = Object.freeze(decoded.obj);
18
+ this.decoded.push(...decoded.values);
17
19
  }
18
20
  base64ToUint8Array(base64) {
19
21
  return BufferHelper.bufferToUint8Array(Buffer.from(base64, 'base64'));
@@ -2,10 +2,17 @@ import { BaseContractProperty } from '../abi/BaseContractProperty.js';
2
2
  import { BitcoinInterface } from '../abi/BitcoinInterface.js';
3
3
  import { BaseContractProperties } from '../abi/interfaces/BaseContractProperties.js';
4
4
  import { BitcoinInterfaceAbi } from '../abi/interfaces/BitcoinInterfaceAbi.js';
5
- import { BitcoinAddressLike } from '../common/CommonTypes.js';
5
+ import { BitcoinAddressLike, DecodedCallResult } from '../common/CommonTypes.js';
6
6
  import { AbstractRpcProvider } from '../providers/AbstractRpcProvider.js';
7
7
  import { IContract } from './interfaces/IContract.js';
8
8
  declare const internal: unique symbol;
9
+ export type ContractDecodedObjectResult = {
10
+ [key: string]: DecodedCallResult;
11
+ };
12
+ export type DecodedOutput = {
13
+ values: Array<DecodedCallResult>;
14
+ obj: ContractDecodedObjectResult;
15
+ };
9
16
  export declare abstract class IBaseContract<T extends BaseContractProperties> implements IContract {
10
17
  readonly address: BitcoinAddressLike;
11
18
  readonly interface: BitcoinInterface;
@@ -113,42 +113,49 @@ export class IBaseContract {
113
113
  }
114
114
  decodeOutput(abi, reader) {
115
115
  const result = [];
116
+ const obj = {};
116
117
  for (let i = 0; i < abi.length; i++) {
117
118
  const type = abi[i].type;
118
119
  const name = abi[i].name;
120
+ let decodedResult;
119
121
  switch (type) {
120
122
  case ABIDataTypes.UINT256:
121
- result.push(reader.readU256());
123
+ decodedResult = reader.readU256();
122
124
  break;
123
125
  case ABIDataTypes.BOOL:
124
- result.push(reader.readBoolean());
126
+ decodedResult = reader.readBoolean();
125
127
  break;
126
128
  case ABIDataTypes.STRING:
127
- result.push(reader.readStringWithLength());
129
+ decodedResult = reader.readStringWithLength();
128
130
  break;
129
131
  case ABIDataTypes.ADDRESS:
130
- result.push(reader.readAddress());
132
+ decodedResult = reader.readAddress();
131
133
  break;
132
134
  case ABIDataTypes.TUPLE:
133
- result.push(reader.readTuple());
135
+ decodedResult = reader.readTuple();
134
136
  break;
135
137
  case ABIDataTypes.UINT8:
136
- result.push(reader.readU8());
138
+ decodedResult = reader.readU8();
137
139
  break;
138
140
  case ABIDataTypes.UINT16:
139
- result.push(reader.readU16());
141
+ decodedResult = reader.readU16();
140
142
  break;
141
143
  case ABIDataTypes.UINT32:
142
- result.push(reader.readU32());
144
+ decodedResult = reader.readU32();
143
145
  break;
144
146
  case ABIDataTypes.BYTES32:
145
- result.push(reader.readBytes(32));
147
+ decodedResult = reader.readBytes(32);
146
148
  break;
147
149
  default:
148
150
  throw new Error(`Unsupported type: ${type} (${name})`);
149
151
  }
152
+ result.push(decodedResult);
153
+ obj[name] = decodedResult;
150
154
  }
151
- return result;
155
+ return {
156
+ values: result,
157
+ obj: obj,
158
+ };
152
159
  }
153
160
  callFunction(element) {
154
161
  return async (...args) => {
@@ -159,7 +166,7 @@ export class IBaseContract {
159
166
  }
160
167
  const decoded = element.outputs
161
168
  ? this.decodeOutput(element.outputs, response.result)
162
- : [];
169
+ : { values: [], obj: {} };
163
170
  response.setDecoded(decoded);
164
171
  return response;
165
172
  };
@@ -34,8 +34,8 @@ const provider = new JSONRpcProvider('https://testnet.opnet.org');
34
34
  },
35
35
  ];
36
36
  const contract = getContract('tb1pth90usc4f528aqphpjrfkkdm4vy8hxnt5gps6aau2nva6pxeshtqqzlt3a', abi, provider);
37
- const res = (await contract.balanceOf('bc1p134a291b21a4ef28c961daee77a75e81cd7c0f00733a152930f76746a3e9'));
38
- console.log('Balance:', res.decoded);
37
+ const balanceExample = (await contract.balanceOf('bc1p134a291b21a4ef28c961daee77a75e81cd7c0f00733a152930f76746a3e9'));
38
+ console.log('Balance:', balanceExample.decoded);
39
39
  const owner = (await contract.owner());
40
- console.log('Owner:', owner.decoded);
40
+ console.log('Owner:', owner.properties);
41
41
  })();
@@ -11,5 +11,6 @@ export declare class DeploymentTransaction extends TransactionBase<OPNetTransact
11
11
  readonly deployerAddress: string;
12
12
  readonly contractSeed: Buffer;
13
13
  readonly contractSaltHash: Buffer;
14
+ readonly from: string;
14
15
  constructor(transaction: IDeploymentTransaction);
15
16
  }
@@ -8,8 +8,10 @@ export class DeploymentTransaction extends TransactionBase {
8
8
  deployerAddress;
9
9
  contractSeed;
10
10
  contractSaltHash;
11
+ from;
11
12
  constructor(transaction) {
12
13
  super(transaction);
14
+ this.from = transaction.from;
13
15
  this.contractAddress = transaction.contractAddress;
14
16
  this.virtualAddress = transaction.virtualAddress;
15
17
  this.bytecode = Buffer.from(transaction.bytecode, 'base64');
@@ -13,5 +13,7 @@ export declare class InteractionTransaction extends TransactionBase<OPNetTransac
13
13
  readonly events: NetEvent[];
14
14
  readonly receipt?: Buffer;
15
15
  readonly receiptProofs?: string[];
16
+ readonly from: string;
17
+ readonly contractAddress: string;
16
18
  constructor(transaction: IInteractionTransaction);
17
19
  }
@@ -9,6 +9,8 @@ export class InteractionTransaction extends TransactionBase {
9
9
  events;
10
10
  receipt;
11
11
  receiptProofs;
12
+ from;
13
+ contractAddress;
12
14
  constructor(transaction) {
13
15
  super(transaction);
14
16
  this.calldata = Buffer.from(transaction.calldata, 'base64');
@@ -16,6 +18,8 @@ export class InteractionTransaction extends TransactionBase {
16
18
  this.contractSecret = Buffer.from(transaction.contractSecret, 'base64');
17
19
  this.interactionPubKey = Buffer.from(transaction.interactionPubKey, 'base64');
18
20
  this.wasCompressed = transaction.wasCompressed;
21
+ this.from = transaction.from;
22
+ this.contractAddress = transaction.contractAddress;
19
23
  this.events = transaction.events;
20
24
  this.receipt = transaction.receipt
21
25
  ? Buffer.from(transaction.receipt, 'base64')
@@ -16,22 +16,26 @@ export interface ITransactionBase<T extends OPNetTransactionTypes> {
16
16
  }
17
17
  export interface IGenericTransaction extends ITransactionBase<OPNetTransactionTypes.Generic> {
18
18
  }
19
- export interface IDeploymentTransaction extends ITransactionBase<OPNetTransactionTypes.Deployment> {
19
+ export interface ICommonTransaction<T extends OPNetTransactionTypes> extends ITransactionBase<T> {
20
+ readonly from: string;
21
+ readonly wasCompressed: boolean;
20
22
  readonly contractAddress: string;
23
+ }
24
+ export interface IDeploymentTransaction extends ICommonTransaction<OPNetTransactionTypes.Deployment> {
21
25
  readonly virtualAddress: string;
22
26
  readonly bytecode: Buffer | string;
23
- readonly wasCompressed: boolean;
24
27
  readonly deployerPubKey: Buffer | string;
25
28
  readonly deployerAddress: string;
26
29
  readonly contractSeed: Buffer | string;
27
30
  readonly contractSaltHash: Buffer | string;
28
31
  }
29
- export interface IInteractionTransaction extends ITransactionBase<OPNetTransactionTypes.Interaction> {
32
+ export interface IInteractionTransaction extends ICommonTransaction<OPNetTransactionTypes.Interaction> {
30
33
  readonly calldata: string | Buffer;
31
34
  readonly senderPubKeyHash: string | Buffer;
32
35
  readonly contractSecret: string | Buffer;
33
36
  readonly interactionPubKey: string | Buffer;
34
37
  readonly wasCompressed: boolean;
38
+ readonly from: string;
35
39
  readonly events: NetEvent[];
36
40
  readonly receipt?: string | Buffer;
37
41
  readonly receiptProofs?: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "type": "module",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "author": "BlobMaster41",
5
5
  "description": "The perfect library for building Bitcoin based applications.",
6
6
  "engines": {
@@ -1,5 +1,6 @@
1
1
  import { BinaryReader, BufferHelper, NetEvent } from '@btc-vision/bsi-binary';
2
2
  import { DecodedCallResult } from '../common/CommonTypes.js';
3
+ import { ContractDecodedObjectResult, DecodedOutput } from './Contract.js';
3
4
  import { IAccessList } from './interfaces/IAccessList.js';
4
5
  import { ICallResultData } from './interfaces/ICallResult.js';
5
6
 
@@ -13,6 +14,7 @@ export class CallResult implements ICallResultData {
13
14
  public readonly accessList: IAccessList;
14
15
 
15
16
  public readonly decoded: Array<DecodedCallResult> = [];
17
+ public properties: ContractDecodedObjectResult = {};
16
18
 
17
19
  constructor(iCallResult: ICallResultData) {
18
20
  this.events = iCallResult.events;
@@ -24,8 +26,10 @@ export class CallResult implements ICallResultData {
24
26
  : iCallResult.result;
25
27
  }
26
28
 
27
- public setDecoded(decoded: Array<DecodedCallResult>): void {
28
- this.decoded.push(...decoded);
29
+ public setDecoded(decoded: DecodedOutput): void {
30
+ this.properties = Object.freeze(decoded.obj);
31
+
32
+ this.decoded.push(...decoded.values);
29
33
  }
30
34
 
31
35
  private base64ToUint8Array(base64: string): Uint8Array {
@@ -15,6 +15,9 @@ import { IContract } from './interfaces/IContract.js';
15
15
  const internal = Symbol.for('_btc_internal');
16
16
  const bitcoinAbiCoder = new ABICoder();
17
17
 
18
+ export type ContractDecodedObjectResult = { [key: string]: DecodedCallResult };
19
+ export type DecodedOutput = { values: Array<DecodedCallResult>; obj: ContractDecodedObjectResult };
20
+
18
21
  /**
19
22
  * Represents the base contract class.
20
23
  * @category Contracts
@@ -172,47 +175,55 @@ export abstract class IBaseContract<T extends BaseContractProperties> implements
172
175
  }
173
176
  }
174
177
 
175
- private decodeOutput(abi: BitcoinAbiValue[], reader: BinaryReader): Array<DecodedCallResult> {
178
+ private decodeOutput(abi: BitcoinAbiValue[], reader: BinaryReader): DecodedOutput {
176
179
  const result: Array<DecodedCallResult> = [];
180
+ const obj: ContractDecodedObjectResult = {};
177
181
 
178
182
  for (let i = 0; i < abi.length; i++) {
179
183
  const type = abi[i].type;
180
184
  const name = abi[i].name;
181
185
 
186
+ let decodedResult: DecodedCallResult;
182
187
  switch (type) {
183
188
  case ABIDataTypes.UINT256:
184
- result.push(reader.readU256());
189
+ decodedResult = reader.readU256();
185
190
  break;
186
191
  case ABIDataTypes.BOOL:
187
- result.push(reader.readBoolean());
192
+ decodedResult = reader.readBoolean();
188
193
  break;
189
194
  case ABIDataTypes.STRING:
190
- result.push(reader.readStringWithLength());
195
+ decodedResult = reader.readStringWithLength();
191
196
  break;
192
197
  case ABIDataTypes.ADDRESS:
193
- result.push(reader.readAddress());
198
+ decodedResult = reader.readAddress();
194
199
  break;
195
200
  case ABIDataTypes.TUPLE:
196
- result.push(reader.readTuple());
201
+ decodedResult = reader.readTuple();
197
202
  break;
198
203
  case ABIDataTypes.UINT8:
199
- result.push(reader.readU8());
204
+ decodedResult = reader.readU8();
200
205
  break;
201
206
  case ABIDataTypes.UINT16:
202
- result.push(reader.readU16());
207
+ decodedResult = reader.readU16();
203
208
  break;
204
209
  case ABIDataTypes.UINT32:
205
- result.push(reader.readU32());
210
+ decodedResult = reader.readU32();
206
211
  break;
207
212
  case ABIDataTypes.BYTES32:
208
- result.push(reader.readBytes(32));
213
+ decodedResult = reader.readBytes(32);
209
214
  break;
210
215
  default:
211
216
  throw new Error(`Unsupported type: ${type} (${name})`);
212
217
  }
218
+
219
+ result.push(decodedResult);
220
+ obj[name] = decodedResult;
213
221
  }
214
222
 
215
- return result;
223
+ return {
224
+ values: result,
225
+ obj: obj,
226
+ };
216
227
  }
217
228
 
218
229
  private callFunction(
@@ -226,9 +237,10 @@ export abstract class IBaseContract<T extends BaseContractProperties> implements
226
237
  return response;
227
238
  }
228
239
 
229
- const decoded = element.outputs
240
+ const decoded: DecodedOutput = element.outputs
230
241
  ? this.decodeOutput(element.outputs, response.result)
231
- : [];
242
+ : { values: [], obj: {} };
243
+
232
244
  response.setDecoded(decoded);
233
245
 
234
246
  return response;
@@ -11,8 +11,6 @@ import { JSONRpcProvider } from '../providers/JSONRpcProvider.js';
11
11
  const provider: JSONRpcProvider = new JSONRpcProvider('https://testnet.opnet.org');
12
12
 
13
13
  interface TestContract extends BaseContractProperties {
14
- giveFreeMoney(bool: true): Promise<BaseContractProperty>;
15
-
16
14
  balanceOf(address: BitcoinAddressLike): Promise<BaseContractProperty>;
17
15
 
18
16
  owner(): Promise<BaseContractProperty>;
@@ -56,14 +54,12 @@ interface TestContract extends BaseContractProperties {
56
54
  provider,
57
55
  );
58
56
 
59
- // 13sBQqJdnAdc7v5tnX3ifYqAMoFX79VfLy
60
- const res: CallResult = (await contract.balanceOf(
57
+ const balanceExample: CallResult = (await contract.balanceOf(
61
58
  'bc1p134a291b21a4ef28c961daee77a75e81cd7c0f00733a152930f76746a3e9',
62
59
  )) as CallResult;
63
60
 
64
- console.log('Balance:', res.decoded);
61
+ console.log('Balance:', balanceExample.decoded);
65
62
 
66
63
  const owner = (await contract.owner()) as CallResult;
67
-
68
- console.log('Owner:', owner.decoded);
64
+ console.log('Owner:', owner.properties);
69
65
  })();
@@ -5,7 +5,7 @@ import { TransactionBase } from './Transaction.js';
5
5
  /**
6
6
  * @description This class is used to provide a deployment transaction.
7
7
  * @class DeploymentTransaction
8
- * @category Transactions
8
+ * @category Transactions<>
9
9
  */
10
10
  export class DeploymentTransaction
11
11
  extends TransactionBase<OPNetTransactionTypes.Deployment>
@@ -23,9 +23,13 @@ export class DeploymentTransaction
23
23
  public readonly contractSeed: Buffer;
24
24
  public readonly contractSaltHash: Buffer;
25
25
 
26
+ public readonly from: string;
27
+
26
28
  constructor(transaction: IDeploymentTransaction) {
27
29
  super(transaction);
28
30
 
31
+ this.from = transaction.from;
32
+
29
33
  this.contractAddress = transaction.contractAddress;
30
34
  this.virtualAddress = transaction.virtualAddress;
31
35
 
@@ -24,6 +24,9 @@ export class InteractionTransaction
24
24
 
25
25
  public readonly receiptProofs?: string[];
26
26
 
27
+ public readonly from: string;
28
+ public readonly contractAddress: string;
29
+
27
30
  constructor(transaction: IInteractionTransaction) {
28
31
  super(transaction);
29
32
 
@@ -33,6 +36,8 @@ export class InteractionTransaction
33
36
  this.interactionPubKey = Buffer.from(transaction.interactionPubKey as string, 'base64');
34
37
 
35
38
  this.wasCompressed = transaction.wasCompressed;
39
+ this.from = transaction.from;
40
+ this.contractAddress = transaction.contractAddress;
36
41
 
37
42
  this.events = transaction.events;
38
43
  this.receipt = transaction.receipt
@@ -32,17 +32,22 @@ export interface ITransactionBase<T extends OPNetTransactionTypes> {
32
32
  */
33
33
  export interface IGenericTransaction extends ITransactionBase<OPNetTransactionTypes.Generic> {}
34
34
 
35
+ export interface ICommonTransaction<T extends OPNetTransactionTypes> extends ITransactionBase<T> {
36
+ readonly from: string;
37
+ readonly wasCompressed: boolean;
38
+ readonly contractAddress: string;
39
+ }
40
+
35
41
  /**
36
42
  * @description This interface represents a deployment transaction.
37
43
  * @interface IDeploymentTransaction
38
44
  * @category ITransactions
39
45
  */
40
- export interface IDeploymentTransaction extends ITransactionBase<OPNetTransactionTypes.Deployment> {
41
- readonly contractAddress: string;
46
+ export interface IDeploymentTransaction
47
+ extends ICommonTransaction<OPNetTransactionTypes.Deployment> {
42
48
  readonly virtualAddress: string;
43
49
 
44
50
  readonly bytecode: Buffer | string;
45
- readonly wasCompressed: boolean;
46
51
 
47
52
  readonly deployerPubKey: Buffer | string;
48
53
  readonly deployerAddress: string;
@@ -57,7 +62,7 @@ export interface IDeploymentTransaction extends ITransactionBase<OPNetTransactio
57
62
  * @category ITransactions
58
63
  */
59
64
  export interface IInteractionTransaction
60
- extends ITransactionBase<OPNetTransactionTypes.Interaction> {
65
+ extends ICommonTransaction<OPNetTransactionTypes.Interaction> {
61
66
  readonly calldata: string | Buffer;
62
67
  readonly senderPubKeyHash: string | Buffer;
63
68
  readonly contractSecret: string | Buffer;
@@ -65,6 +70,8 @@ export interface IInteractionTransaction
65
70
 
66
71
  readonly wasCompressed: boolean;
67
72
 
73
+ readonly from: string;
74
+
68
75
  readonly events: NetEvent[];
69
76
  readonly receipt?: string | Buffer;
70
77
  readonly receiptProofs?: string[];