opnet 1.0.0 → 1.0.2

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 (55) hide show
  1. package/.idea/OPNet.iml +15 -0
  2. package/.idea/bsc.iml +14 -0
  3. package/.idea/codeStyles/Project.xml +101 -0
  4. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  5. package/.idea/inspectionProfiles/Project_Default.xml +7 -0
  6. package/.idea/markdown.xml +7 -0
  7. package/.idea/modules.xml +1 -1
  8. package/.idea/motoswap.iml +12 -0
  9. package/.idea/vcs.xml +6 -0
  10. package/README.md +2 -3
  11. package/build/block/Block.d.ts +27 -0
  12. package/build/block/Block.js +68 -0
  13. package/build/index.d.ts +11 -0
  14. package/build/index.js +11 -2
  15. package/build/interfaces/Block.d.ts +0 -0
  16. package/build/interfaces/Block.js +1 -0
  17. package/build/interfaces/IBlock.d.ts +0 -0
  18. package/build/interfaces/IBlock.js +1 -0
  19. package/build/interfaces/blocks/IBlock.d.ts +28 -0
  20. package/build/interfaces/blocks/IBlock.js +1 -0
  21. package/build/interfaces/opnet/OPNetTransactionTypes.d.ts +5 -0
  22. package/build/interfaces/opnet/OPNetTransactionTypes.js +6 -0
  23. package/build/interfaces/transactions/ITransaction.d.ts +31 -0
  24. package/build/interfaces/transactions/ITransaction.js +1 -0
  25. package/build/providers/JSONRpcProvider.d.ts +12 -0
  26. package/build/providers/JSONRpcProvider.js +48 -0
  27. package/build/scripts/test.d.ts +1 -0
  28. package/build/scripts/test.js +8 -0
  29. package/build/transactions/DeploymentTransaction.d.ts +6 -0
  30. package/build/transactions/DeploymentTransaction.js +6 -0
  31. package/build/transactions/GenericTransaction.d.ts +6 -0
  32. package/build/transactions/GenericTransaction.js +6 -0
  33. package/build/transactions/InteractionTransaction.d.ts +16 -0
  34. package/build/transactions/InteractionTransaction.js +24 -0
  35. package/build/transactions/Transaction.d.ts +17 -0
  36. package/build/transactions/Transaction.js +24 -0
  37. package/build/transactions/TransactionInput.d.ts +16 -0
  38. package/build/transactions/TransactionInput.js +14 -0
  39. package/build/transactions/TransactionOutput.d.ts +19 -0
  40. package/build/transactions/TransactionOutput.js +16 -0
  41. package/package.json +5 -1
  42. package/src/block/Block.ts +104 -0
  43. package/src/index.ts +11 -4
  44. package/src/interfaces/blocks/IBlock.ts +38 -0
  45. package/src/interfaces/opnet/OPNetTransactionTypes.ts +5 -0
  46. package/src/interfaces/transactions/ITransaction.ts +41 -0
  47. package/src/providers/JSONRpcProvider.ts +67 -0
  48. package/src/scripts/test.ts +11 -0
  49. package/src/transactions/DeploymentTransaction.ts +12 -0
  50. package/src/transactions/GenericTransaction.ts +12 -0
  51. package/src/transactions/InteractionTransaction.ts +39 -0
  52. package/src/transactions/Transaction.ts +42 -0
  53. package/src/transactions/TransactionInput.ts +31 -0
  54. package/src/transactions/TransactionOutput.ts +33 -0
  55. /package/.idea/{opnet.iml → bsi-binary.iml} +0 -0
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ <excludeFolder url="file://$MODULE_DIR$/build" />
9
+ <excludeFolder url="file://$MODULE_DIR$/packages" />
10
+ <excludeFolder url="file://$MODULE_DIR$/cjs" />
11
+ </content>
12
+ <orderEntry type="inheritedJdk" />
13
+ <orderEntry type="sourceFolder" forTests="false" />
14
+ </component>
15
+ </module>
package/.idea/bsc.iml ADDED
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ <excludeFolder url="file://$MODULE_DIR$/build" />
9
+ <excludeFolder url="file://$MODULE_DIR$/cjs" />
10
+ </content>
11
+ <orderEntry type="inheritedJdk" />
12
+ <orderEntry type="sourceFolder" forTests="false" />
13
+ </component>
14
+ </module>
@@ -0,0 +1,101 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <code_scheme name="Project" version="173">
3
+ <HTMLCodeStyleSettings>
4
+ <option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
5
+ <option name="HTML_QUOTE_STYLE" value="Single" />
6
+ <option name="HTML_ENFORCE_QUOTES" value="true" />
7
+ </HTMLCodeStyleSettings>
8
+ <JSCodeStyleSettings version="0">
9
+ <option name="FORCE_SEMICOLON_STYLE" value="true" />
10
+ <option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
11
+ <option name="USE_DOUBLE_QUOTES" value="false" />
12
+ <option name="FORCE_QUOTE_STYlE" value="true" />
13
+ <option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
14
+ <option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
15
+ <option name="SPACES_WITHIN_IMPORTS" value="true" />
16
+ <option name="IMPORT_SORT_MODULE_NAME" value="true" />
17
+ </JSCodeStyleSettings>
18
+ <Markdown>
19
+ <option name="KEEP_LINE_BREAKS_INSIDE_TEXT_BLOCKS" value="false" />
20
+ </Markdown>
21
+ <TypeScriptCodeStyleSettings version="0">
22
+ <option name="FORCE_SEMICOLON_STYLE" value="true" />
23
+ <option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
24
+ <option name="USE_DOUBLE_QUOTES" value="false" />
25
+ <option name="FORCE_QUOTE_STYlE" value="true" />
26
+ <option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
27
+ <option name="USE_EXPLICIT_JS_EXTENSION" value="TRUE" />
28
+ <option name="VAR_DECLARATION_WRAP" value="5" />
29
+ <option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
30
+ <option name="SPACES_WITHIN_IMPORTS" value="true" />
31
+ <option name="IMPORT_SORT_MODULE_NAME" value="true" />
32
+ </TypeScriptCodeStyleSettings>
33
+ <VueCodeStyleSettings>
34
+ <option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
35
+ <option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
36
+ </VueCodeStyleSettings>
37
+ <codeStyleSettings language="HTML">
38
+ <option name="SOFT_MARGINS" value="100" />
39
+ <indentOptions>
40
+ <option name="CONTINUATION_INDENT_SIZE" value="4" />
41
+ </indentOptions>
42
+ </codeStyleSettings>
43
+ <codeStyleSettings language="JSON">
44
+ <indentOptions>
45
+ <option name="INDENT_SIZE" value="4" />
46
+ </indentOptions>
47
+ </codeStyleSettings>
48
+ <codeStyleSettings language="JavaScript">
49
+ <option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
50
+ <option name="ALIGN_MULTILINE_BINARY_OPERATION" value="true" />
51
+ <option name="CALL_PARAMETERS_WRAP" value="5" />
52
+ <option name="PREFER_PARAMETERS_WRAP" value="true" />
53
+ <option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
54
+ <option name="CALL_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
55
+ <option name="METHOD_PARAMETERS_WRAP" value="5" />
56
+ <option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
57
+ <option name="METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
58
+ <option name="BINARY_OPERATION_WRAP" value="5" />
59
+ <option name="SOFT_MARGINS" value="100" />
60
+ </codeStyleSettings>
61
+ <codeStyleSettings language="Markdown">
62
+ <option name="RIGHT_MARGIN" value="80" />
63
+ <option name="WRAP_ON_TYPING" value="1" />
64
+ <option name="SOFT_MARGINS" value="80" />
65
+ <indentOptions>
66
+ <option name="INDENT_SIZE" value="2" />
67
+ <option name="CONTINUATION_INDENT_SIZE" value="4" />
68
+ <option name="TAB_SIZE" value="2" />
69
+ </indentOptions>
70
+ </codeStyleSettings>
71
+ <codeStyleSettings language="TypeScript">
72
+ <option name="ALIGN_MULTILINE_CHAINED_METHODS" value="true" />
73
+ <option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
74
+ <option name="ALIGN_MULTILINE_BINARY_OPERATION" value="true" />
75
+ <option name="ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION" value="true" />
76
+ <option name="CALL_PARAMETERS_WRAP" value="5" />
77
+ <option name="PREFER_PARAMETERS_WRAP" value="true" />
78
+ <option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
79
+ <option name="CALL_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
80
+ <option name="METHOD_PARAMETERS_WRAP" value="5" />
81
+ <option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
82
+ <option name="METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
83
+ <option name="METHOD_CALL_CHAIN_WRAP" value="5" />
84
+ <option name="PARENTHESES_EXPRESSION_LPAREN_WRAP" value="true" />
85
+ <option name="PARENTHESES_EXPRESSION_RPAREN_WRAP" value="true" />
86
+ <option name="FOR_STATEMENT_LPAREN_ON_NEXT_LINE" value="true" />
87
+ <option name="FOR_STATEMENT_RPAREN_ON_NEXT_LINE" value="true" />
88
+ <option name="ARRAY_INITIALIZER_WRAP" value="5" />
89
+ <option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" />
90
+ <option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" />
91
+ <option name="SOFT_MARGINS" value="100" />
92
+ </codeStyleSettings>
93
+ <codeStyleSettings language="Vue">
94
+ <option name="SOFT_MARGINS" value="100" />
95
+ <indentOptions>
96
+ <option name="INDENT_SIZE" value="4" />
97
+ <option name="TAB_SIZE" value="4" />
98
+ </indentOptions>
99
+ </codeStyleSettings>
100
+ </code_scheme>
101
+ </component>
@@ -0,0 +1,5 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <state>
3
+ <option name="USE_PER_PROJECT_SETTINGS" value="true" />
4
+ </state>
5
+ </component>
@@ -0,0 +1,7 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
5
+ <inspection_tool class="TsLint" enabled="true" level="WARNING" enabled_by_default="true" />
6
+ </profile>
7
+ </component>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="MarkdownSettings">
4
+ <option name="areInjectionsEnabled" value="false" />
5
+ <option name="showProblemsInCodeBlocks" value="false" />
6
+ </component>
7
+ </project>
package/.idea/modules.xml CHANGED
@@ -2,7 +2,7 @@
2
2
  <project version="4">
3
3
  <component name="ProjectModuleManager">
4
4
  <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/opnet.iml" filepath="$PROJECT_DIR$/.idea/opnet.iml" />
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/OPNet.iml" filepath="$PROJECT_DIR$/.idea/OPNet.iml" />
6
6
  </modules>
7
7
  </component>
8
8
  </project>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ </content>
9
+ <orderEntry type="inheritedJdk" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ </component>
12
+ </module>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
package/README.md CHANGED
@@ -46,14 +46,13 @@ npm i opnet
46
46
 
47
47
  ## Usage
48
48
 
49
- Refer to the `docs/` directory for detailed guides on how to use the BSI Transaction Builder. Start
49
+ Refer to the `docs/` directory for detailed guides on how to use OPNet. Start
50
50
  with `getting_started.md` and explore `api_reference.md` for comprehensive information about the functions available.
51
51
 
52
52
  ## Contribution
53
53
 
54
54
  Contributions are welcome! Please read through the `CONTRIBUTING.md` file for guidelines on how to submit issues,
55
- feature requests, and pull requests. We appreciate your input and encourage you to help us improve the BSI Transaction
56
- Builder.
55
+ feature requests, and pull requests. We appreciate your input and encourage you to help us improve OPNet.
57
56
 
58
57
  ## License
59
58
 
@@ -0,0 +1,27 @@
1
+ import { BigNumberish } from 'ethers';
2
+ import { BlockHeaderChecksumProof, IBlock } from '../interfaces/blocks/IBlock.js';
3
+ import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
4
+ import { TransactionBase } from '../transactions/Transaction.js';
5
+ export declare class Block implements IBlock {
6
+ readonly height: BigNumberish;
7
+ readonly hash: string;
8
+ readonly previousBlockHash: string;
9
+ readonly previousBlockChecksum: string;
10
+ readonly bits: string;
11
+ readonly nonce: number;
12
+ readonly version: number;
13
+ readonly size: number;
14
+ readonly txCount: number;
15
+ readonly weight: number;
16
+ readonly strippedSize: number;
17
+ readonly time: number;
18
+ readonly medianTime: number;
19
+ readonly checksumRoot: string;
20
+ readonly merkleRoot: string;
21
+ readonly storageRoot: string;
22
+ readonly receiptRoot: string;
23
+ readonly checksumProofs: BlockHeaderChecksumProof;
24
+ readonly transactions?: TransactionBase<OPNetTransactionTypes>[];
25
+ constructor(block: IBlock);
26
+ private getTransactions;
27
+ }
@@ -0,0 +1,68 @@
1
+ import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
2
+ import { DeploymentTransaction } from '../transactions/DeploymentTransaction.js';
3
+ import { GenericTransaction } from '../transactions/GenericTransaction.js';
4
+ import { InteractionTransaction } from '../transactions/InteractionTransaction.js';
5
+ export class Block {
6
+ height;
7
+ hash;
8
+ previousBlockHash;
9
+ previousBlockChecksum;
10
+ bits;
11
+ nonce;
12
+ version;
13
+ size;
14
+ txCount;
15
+ weight;
16
+ strippedSize;
17
+ time;
18
+ medianTime;
19
+ checksumRoot;
20
+ merkleRoot;
21
+ storageRoot;
22
+ receiptRoot;
23
+ checksumProofs;
24
+ transactions;
25
+ constructor(block) {
26
+ this.height = BigInt(block.height.toString());
27
+ this.hash = block.hash;
28
+ this.previousBlockHash = block.previousBlockHash;
29
+ this.previousBlockChecksum = block.previousBlockChecksum;
30
+ this.bits = block.bits;
31
+ this.nonce = block.nonce;
32
+ this.version = block.version;
33
+ this.size = block.size;
34
+ this.txCount = block.txCount;
35
+ this.weight = block.weight;
36
+ this.strippedSize = block.strippedSize;
37
+ this.time = block.time;
38
+ this.medianTime = block.medianTime;
39
+ this.checksumRoot = block.checksumRoot;
40
+ this.merkleRoot = block.merkleRoot;
41
+ this.storageRoot = block.storageRoot;
42
+ this.receiptRoot = block.receiptRoot;
43
+ this.checksumProofs = block.checksumProofs;
44
+ this.transactions = this.getTransactions(block.transactions);
45
+ }
46
+ getTransactions(transactions) {
47
+ if (!transactions) {
48
+ return [];
49
+ }
50
+ const transactionArray = [];
51
+ for (let transaction of transactions) {
52
+ switch (transaction.OPNetType) {
53
+ case OPNetTransactionTypes.Generic:
54
+ transactionArray.push(new GenericTransaction(transaction));
55
+ break;
56
+ case OPNetTransactionTypes.Interaction:
57
+ transactionArray.push(new InteractionTransaction(transaction));
58
+ break;
59
+ case OPNetTransactionTypes.Deployment:
60
+ transactionArray.push(new DeploymentTransaction(transaction));
61
+ break;
62
+ default:
63
+ throw new Error('Unknown transaction type');
64
+ }
65
+ }
66
+ return transactionArray;
67
+ }
68
+ }
package/build/index.d.ts CHANGED
@@ -0,0 +1,11 @@
1
+ export * from './interfaces/opnet/OPNetTransactionTypes.js';
2
+ export * from './interfaces/transactions/ITransaction.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 './block/Block.js';
11
+ export * from './interfaces/blocks/IBlock.js';
package/build/index.js CHANGED
@@ -1,2 +1,11 @@
1
- "use strict";
2
- console.log(`The start of everything is the end of something else. The end of everything is the start of something else.`);
1
+ export * from './interfaces/opnet/OPNetTransactionTypes.js';
2
+ export * from './interfaces/transactions/ITransaction.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 './block/Block.js';
11
+ export * from './interfaces/blocks/IBlock.js';
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,28 @@
1
+ import { BigNumberish } from 'ethers';
2
+ import { TransactionBase } from '../../transactions/Transaction.js';
3
+ import { OPNetTransactionTypes } from '../opnet/OPNetTransactionTypes.js';
4
+ import { ITransaction } from '../transactions/ITransaction.js';
5
+ export type BlockHeaderChecksumProof = Array<[number, string[]]>;
6
+ export interface IBlockCommon {
7
+ height: string | BigNumberish;
8
+ hash: string;
9
+ previousBlockHash: string;
10
+ previousBlockChecksum: string;
11
+ bits: string;
12
+ nonce: number;
13
+ version: number;
14
+ size: number;
15
+ txCount: number;
16
+ weight: number;
17
+ strippedSize: number;
18
+ time: number;
19
+ medianTime: number;
20
+ checksumRoot: string;
21
+ merkleRoot: string;
22
+ storageRoot: string;
23
+ receiptRoot: string;
24
+ checksumProofs: BlockHeaderChecksumProof;
25
+ }
26
+ export interface IBlock extends IBlockCommon {
27
+ transactions?: ITransaction[] | TransactionBase<OPNetTransactionTypes>[];
28
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ export declare enum OPNetTransactionTypes {
2
+ Generic = "Generic",
3
+ Deployment = "Deployment",
4
+ Interaction = "Interaction"
5
+ }
@@ -0,0 +1,6 @@
1
+ export var OPNetTransactionTypes;
2
+ (function (OPNetTransactionTypes) {
3
+ OPNetTransactionTypes["Generic"] = "Generic";
4
+ OPNetTransactionTypes["Deployment"] = "Deployment";
5
+ OPNetTransactionTypes["Interaction"] = "Interaction";
6
+ })(OPNetTransactionTypes || (OPNetTransactionTypes = {}));
@@ -0,0 +1,31 @@
1
+ /// <reference types="node" />
2
+ import { NetEvent } from '@btc-vision/bsi-binary';
3
+ import { BigNumberish } from 'ethers';
4
+ import { ITransactionInput, TransactionInput } from '../../transactions/TransactionInput.js';
5
+ import { ITransactionOutput, TransactionOutput } from '../../transactions/TransactionOutput.js';
6
+ import { OPNetTransactionTypes } from '../opnet/OPNetTransactionTypes.js';
7
+ export interface ITransactionBase<T extends OPNetTransactionTypes> {
8
+ readonly id: string;
9
+ readonly hash: string;
10
+ readonly index: number;
11
+ readonly burnedBitcoin: string | BigNumberish;
12
+ readonly revert?: string | Buffer;
13
+ readonly inputs: ITransactionInput[] | TransactionInput[];
14
+ readonly outputs: ITransactionOutput[] | TransactionOutput[];
15
+ readonly OPNetType: T;
16
+ }
17
+ export interface IGenericTransaction extends ITransactionBase<OPNetTransactionTypes.Generic> {
18
+ }
19
+ export interface IDeploymentTransaction extends ITransactionBase<OPNetTransactionTypes.Deployment> {
20
+ }
21
+ export interface IInteractionTransaction extends ITransactionBase<OPNetTransactionTypes.Interaction> {
22
+ readonly calldata: string | Buffer;
23
+ readonly senderPubKeyHash: string | Buffer;
24
+ readonly contractSecret: string | Buffer;
25
+ readonly interactionPubKey: string | Buffer;
26
+ readonly wasCompressed: boolean;
27
+ readonly events: NetEvent[];
28
+ readonly receipt?: string | Buffer;
29
+ readonly receiptProofs?: string[];
30
+ }
31
+ export type ITransaction = IDeploymentTransaction | IInteractionTransaction | IGenericTransaction;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import type { BlockTag } from 'ethers/src.ts/providers/provider.js';
2
+ import { Block } from '../block/Block.js';
3
+ export declare class JSONRpcProvider {
4
+ private readonly provider;
5
+ private readonly url;
6
+ private nextId;
7
+ constructor(url: string);
8
+ private providerUrl;
9
+ getBlockNumber(): Promise<number>;
10
+ getBlock(blockNumber: BlockTag | string, prefetchTxs?: boolean): Promise<Block>;
11
+ private buildJsonRpcPayload;
12
+ }
@@ -0,0 +1,48 @@
1
+ import { JsonRpcProvider } from 'ethers';
2
+ import { Block } from '../block/Block.js';
3
+ export class JSONRpcProvider {
4
+ provider;
5
+ url;
6
+ nextId = 0;
7
+ constructor(url) {
8
+ this.url = this.providerUrl(url);
9
+ this.provider = new JsonRpcProvider(this.url);
10
+ }
11
+ providerUrl(url) {
12
+ url = url.trim();
13
+ if (url.endsWith('/')) {
14
+ return url.slice(0, -1);
15
+ }
16
+ if (url.includes('api/v1/json-rpc')) {
17
+ return url;
18
+ }
19
+ else {
20
+ return `${url}/api/v1/json-rpc`;
21
+ }
22
+ }
23
+ async getBlockNumber() {
24
+ return await this.provider.getBlockNumber();
25
+ }
26
+ async getBlock(blockNumber, prefetchTxs = false) {
27
+ const method = typeof blockNumber === 'string' ? 'btc_getBlockByHash' : 'btc_getBlockByNumber';
28
+ const payload = this.buildJsonRpcPayload(method, [
29
+ blockNumber,
30
+ prefetchTxs,
31
+ ]);
32
+ const blockData = await this.provider._send(payload);
33
+ const block = blockData.shift();
34
+ if (!block) {
35
+ throw new Error('Block not found');
36
+ }
37
+ const result = block.result;
38
+ return new Block(result);
39
+ }
40
+ buildJsonRpcPayload(method, params) {
41
+ return {
42
+ method: method,
43
+ params: params,
44
+ id: this.nextId++,
45
+ jsonrpc: '2.0',
46
+ };
47
+ }
48
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { JSONRpcProvider } from '../providers/JSONRpcProvider.js';
2
+ const provider = new JSONRpcProvider('http://localhost:9001');
3
+ (async () => {
4
+ const blockNumber = await provider.getBlockNumber();
5
+ console.log('Current network height:', blockNumber);
6
+ const block = await provider.getBlock(blockNumber, true);
7
+ console.log('Block ->', block);
8
+ })();
@@ -0,0 +1,6 @@
1
+ import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
2
+ import { IDeploymentTransaction } from '../interfaces/transactions/ITransaction.js';
3
+ import { TransactionBase } from './Transaction.js';
4
+ export declare class DeploymentTransaction extends TransactionBase<OPNetTransactionTypes.Deployment> implements IDeploymentTransaction {
5
+ constructor(transaction: IDeploymentTransaction);
6
+ }
@@ -0,0 +1,6 @@
1
+ import { TransactionBase } from './Transaction.js';
2
+ export class DeploymentTransaction extends TransactionBase {
3
+ constructor(transaction) {
4
+ super(transaction);
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
2
+ import { IGenericTransaction } from '../interfaces/transactions/ITransaction.js';
3
+ import { TransactionBase } from './Transaction.js';
4
+ export declare class GenericTransaction extends TransactionBase<OPNetTransactionTypes.Generic> implements IGenericTransaction {
5
+ constructor(transaction: IGenericTransaction);
6
+ }
@@ -0,0 +1,6 @@
1
+ import { TransactionBase } from './Transaction.js';
2
+ export class GenericTransaction extends TransactionBase {
3
+ constructor(transaction) {
4
+ super(transaction);
5
+ }
6
+ }
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" />
2
+ import { NetEvent } from '@btc-vision/bsi-binary';
3
+ import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
4
+ import { IInteractionTransaction } from '../interfaces/transactions/ITransaction.js';
5
+ import { TransactionBase } from './Transaction.js';
6
+ export declare class InteractionTransaction extends TransactionBase<OPNetTransactionTypes.Interaction> implements IInteractionTransaction {
7
+ readonly calldata: Buffer;
8
+ readonly senderPubKeyHash: Buffer;
9
+ readonly contractSecret: Buffer;
10
+ readonly interactionPubKey: Buffer;
11
+ readonly wasCompressed: boolean;
12
+ readonly events: NetEvent[];
13
+ readonly receipt?: Buffer;
14
+ readonly receiptProofs?: string[];
15
+ constructor(transaction: IInteractionTransaction);
16
+ }
@@ -0,0 +1,24 @@
1
+ import { TransactionBase } from './Transaction.js';
2
+ export class InteractionTransaction extends TransactionBase {
3
+ calldata;
4
+ senderPubKeyHash;
5
+ contractSecret;
6
+ interactionPubKey;
7
+ wasCompressed;
8
+ events;
9
+ receipt;
10
+ receiptProofs;
11
+ constructor(transaction) {
12
+ super(transaction);
13
+ this.calldata = Buffer.from(transaction.calldata, 'base64');
14
+ this.senderPubKeyHash = Buffer.from(transaction.senderPubKeyHash, 'base64');
15
+ this.contractSecret = Buffer.from(transaction.contractSecret, 'base64');
16
+ this.interactionPubKey = Buffer.from(transaction.interactionPubKey, 'base64');
17
+ this.wasCompressed = transaction.wasCompressed;
18
+ this.events = transaction.events;
19
+ this.receipt = transaction.receipt
20
+ ? Buffer.from(transaction.receipt, 'base64')
21
+ : undefined;
22
+ this.receiptProofs = transaction.receiptProofs;
23
+ }
24
+ }
@@ -0,0 +1,17 @@
1
+ /// <reference types="node" />
2
+ import { BigNumberish } from 'ethers';
3
+ import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
4
+ import { ITransactionBase } from '../interfaces/transactions/ITransaction.js';
5
+ import { TransactionInput } from './TransactionInput.js';
6
+ import { TransactionOutput } from './TransactionOutput.js';
7
+ export declare abstract class TransactionBase<T extends OPNetTransactionTypes> implements ITransactionBase<T> {
8
+ readonly id: string;
9
+ readonly hash: string;
10
+ readonly index: number;
11
+ readonly burnedBitcoin: BigNumberish;
12
+ readonly revert?: Buffer;
13
+ readonly inputs: TransactionInput[];
14
+ readonly outputs: TransactionOutput[];
15
+ readonly OPNetType: T;
16
+ protected constructor(transaction: ITransactionBase<T>);
17
+ }
@@ -0,0 +1,24 @@
1
+ import { TransactionInput } from './TransactionInput.js';
2
+ import { TransactionOutput } from './TransactionOutput.js';
3
+ export class TransactionBase {
4
+ id;
5
+ hash;
6
+ index;
7
+ burnedBitcoin;
8
+ revert;
9
+ inputs;
10
+ outputs;
11
+ OPNetType;
12
+ constructor(transaction) {
13
+ this.id = transaction.id;
14
+ this.hash = transaction.hash;
15
+ this.index = transaction.index;
16
+ this.burnedBitcoin = transaction.burnedBitcoin;
17
+ this.inputs = transaction.inputs.map((input) => new TransactionInput(input));
18
+ this.outputs = transaction.outputs.map((output) => new TransactionOutput(output));
19
+ this.revert = transaction.revert
20
+ ? Buffer.from(transaction.revert, 'base64')
21
+ : undefined;
22
+ this.OPNetType = transaction.OPNetType;
23
+ }
24
+ }
@@ -0,0 +1,16 @@
1
+ import { ScriptSig } from '@btc-vision/bsi-bitcoin-rpc';
2
+ export interface ITransactionInput {
3
+ readonly originalTransactionId: string | undefined;
4
+ readonly outputTransactionIndex: number | undefined;
5
+ readonly scriptSignature: ScriptSig | undefined;
6
+ readonly sequenceId: number;
7
+ readonly transactionInWitness?: string[];
8
+ }
9
+ export declare class TransactionInput implements ITransactionInput {
10
+ readonly originalTransactionId: string | undefined;
11
+ readonly outputTransactionIndex: number | undefined;
12
+ readonly scriptSignature: ScriptSig | undefined;
13
+ readonly sequenceId: number;
14
+ readonly transactionInWitness: string[];
15
+ constructor(data: ITransactionInput);
16
+ }
@@ -0,0 +1,14 @@
1
+ export class TransactionInput {
2
+ originalTransactionId;
3
+ outputTransactionIndex;
4
+ scriptSignature;
5
+ sequenceId;
6
+ transactionInWitness = [];
7
+ constructor(data) {
8
+ this.originalTransactionId = data.originalTransactionId;
9
+ this.outputTransactionIndex = data.outputTransactionIndex;
10
+ this.scriptSignature = data.scriptSignature;
11
+ this.sequenceId = data.sequenceId;
12
+ this.transactionInWitness = data.transactionInWitness || [];
13
+ }
14
+ }
@@ -0,0 +1,19 @@
1
+ /// <reference types="node" />
2
+ import { ScriptPubKey } from '@btc-vision/bsi-bitcoin-rpc';
3
+ export interface ITransactionOutput {
4
+ readonly index: number;
5
+ readonly scriptPubKey: {
6
+ hex: string;
7
+ addresses?: string[];
8
+ address?: string;
9
+ };
10
+ readonly value: string;
11
+ }
12
+ export declare class TransactionOutput {
13
+ readonly value: bigint;
14
+ readonly index: number;
15
+ readonly scriptPubKey: ScriptPubKey;
16
+ readonly script: Array<number | Buffer> | null;
17
+ constructor(data: ITransactionOutput);
18
+ private convertValue;
19
+ }
@@ -0,0 +1,16 @@
1
+ import { script } from 'bitcoinjs-lib';
2
+ export class TransactionOutput {
3
+ value;
4
+ index;
5
+ scriptPubKey;
6
+ script;
7
+ constructor(data) {
8
+ this.value = this.convertValue(data.value);
9
+ this.index = data.index;
10
+ this.scriptPubKey = data.scriptPubKey;
11
+ this.script = script.decompile(Buffer.from(this.scriptPubKey.hex, 'hex'));
12
+ }
13
+ convertValue(value) {
14
+ return BigInt(value);
15
+ }
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "type": "module",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "author": "BlobMaster41",
5
5
  "description": "The perfect library for building Bitcoin based applications.",
6
6
  "engines": {
@@ -44,6 +44,7 @@
44
44
  "devDependencies": {
45
45
  "@babel/preset-env": "^7.24.3",
46
46
  "@types/node": "^20.11.30",
47
+ "@types/ws": "^8.5.10",
47
48
  "eslint": "^8.57.0",
48
49
  "jest": "^29.7.0",
49
50
  "prettier": "^3.2.5",
@@ -51,10 +52,13 @@
51
52
  "typescript-eslint": "^7.4.0"
52
53
  },
53
54
  "dependencies": {
55
+ "@btc-vision/bsi-binary": "^1.0.6",
56
+ "@btc-vision/bsi-bitcoin-rpc": "^1.0.8",
54
57
  "@jest/types": "^29.6.3",
55
58
  "@types/jest": "^29.5.12",
56
59
  "babel-plugin-transform-import-meta": "^2.2.1",
57
60
  "bitcoinjs-lib": "^6.1.5",
61
+ "ethers": "^6.12.1",
58
62
  "gulp": "^4.0.2",
59
63
  "gulp-cached": "^1.1.1",
60
64
  "gulp-logger": "^0.0.2",
@@ -0,0 +1,104 @@
1
+ import { BigNumberish } from 'ethers';
2
+ import { BlockHeaderChecksumProof, IBlock } from '../interfaces/blocks/IBlock.js';
3
+ import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
4
+ import {
5
+ IDeploymentTransaction,
6
+ IGenericTransaction,
7
+ IInteractionTransaction,
8
+ ITransaction,
9
+ } from '../interfaces/transactions/ITransaction.js';
10
+ import { DeploymentTransaction } from '../transactions/DeploymentTransaction.js';
11
+ import { GenericTransaction } from '../transactions/GenericTransaction.js';
12
+ import { InteractionTransaction } from '../transactions/InteractionTransaction.js';
13
+ import { TransactionBase } from '../transactions/Transaction.js';
14
+
15
+ export class Block implements IBlock {
16
+ public readonly height: BigNumberish;
17
+
18
+ public readonly hash: string;
19
+ public readonly previousBlockHash: string;
20
+ public readonly previousBlockChecksum: string;
21
+
22
+ public readonly bits: string;
23
+ public readonly nonce: number;
24
+ public readonly version: number;
25
+ public readonly size: number;
26
+ public readonly txCount: number;
27
+
28
+ public readonly weight: number;
29
+ public readonly strippedSize: number;
30
+
31
+ public readonly time: number;
32
+ public readonly medianTime: number;
33
+
34
+ public readonly checksumRoot: string;
35
+ public readonly merkleRoot: string;
36
+ public readonly storageRoot: string;
37
+ public readonly receiptRoot: string;
38
+
39
+ public readonly checksumProofs: BlockHeaderChecksumProof;
40
+
41
+ public readonly transactions?: TransactionBase<OPNetTransactionTypes>[];
42
+
43
+ constructor(block: IBlock) {
44
+ this.height = BigInt(block.height.toString());
45
+
46
+ this.hash = block.hash;
47
+ this.previousBlockHash = block.previousBlockHash;
48
+ this.previousBlockChecksum = block.previousBlockChecksum;
49
+
50
+ this.bits = block.bits;
51
+ this.nonce = block.nonce;
52
+ this.version = block.version;
53
+ this.size = block.size;
54
+ this.txCount = block.txCount;
55
+
56
+ this.weight = block.weight;
57
+ this.strippedSize = block.strippedSize;
58
+
59
+ this.time = block.time;
60
+ this.medianTime = block.medianTime;
61
+
62
+ this.checksumRoot = block.checksumRoot;
63
+ this.merkleRoot = block.merkleRoot;
64
+ this.storageRoot = block.storageRoot;
65
+ this.receiptRoot = block.receiptRoot;
66
+
67
+ this.checksumProofs = block.checksumProofs;
68
+
69
+ this.transactions = this.getTransactions(block.transactions as ITransaction[]);
70
+ }
71
+
72
+ private getTransactions(
73
+ transactions: ITransaction[],
74
+ ): TransactionBase<OPNetTransactionTypes>[] {
75
+ if (!transactions) {
76
+ return [];
77
+ }
78
+
79
+ const transactionArray: TransactionBase<OPNetTransactionTypes>[] = [];
80
+ for (let transaction of transactions) {
81
+ switch (transaction.OPNetType) {
82
+ case OPNetTransactionTypes.Generic:
83
+ transactionArray.push(
84
+ new GenericTransaction(transaction as IGenericTransaction),
85
+ );
86
+ break;
87
+ case OPNetTransactionTypes.Interaction:
88
+ transactionArray.push(
89
+ new InteractionTransaction(transaction as IInteractionTransaction),
90
+ );
91
+ break;
92
+ case OPNetTransactionTypes.Deployment:
93
+ transactionArray.push(
94
+ new DeploymentTransaction(transaction as IDeploymentTransaction),
95
+ );
96
+ break;
97
+ default:
98
+ throw new Error('Unknown transaction type');
99
+ }
100
+ }
101
+
102
+ return transactionArray;
103
+ }
104
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,12 @@
1
- /** First commit made to reserve the project name. */
1
+ export * from './interfaces/opnet/OPNetTransactionTypes.js';
2
+ export * from './interfaces/transactions/ITransaction.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';
2
10
 
3
- console.log(
4
- `The start of everything is the end of something else. The end of everything is the start of something else.`,
5
- );
11
+ export * from './block/Block.js';
12
+ export * from './interfaces/blocks/IBlock.js';
@@ -0,0 +1,38 @@
1
+ import { BigNumberish } from 'ethers';
2
+ import { TransactionBase } from '../../transactions/Transaction.js';
3
+ import { OPNetTransactionTypes } from '../opnet/OPNetTransactionTypes.js';
4
+ import { ITransaction } from '../transactions/ITransaction.js';
5
+
6
+ export type BlockHeaderChecksumProof = Array<[number, string[]]>;
7
+
8
+ export interface IBlockCommon {
9
+ height: string | BigNumberish;
10
+ hash: string;
11
+
12
+ previousBlockHash: string;
13
+ previousBlockChecksum: string;
14
+
15
+ bits: string;
16
+ nonce: number;
17
+ version: number;
18
+ size: number;
19
+ txCount: number;
20
+
21
+ weight: number;
22
+ strippedSize: number;
23
+
24
+ time: number;
25
+ medianTime: number;
26
+
27
+ /** Allows us to verify that the block is correct and not regenerated. */
28
+ checksumRoot: string;
29
+ merkleRoot: string;
30
+ storageRoot: string;
31
+ receiptRoot: string;
32
+
33
+ checksumProofs: BlockHeaderChecksumProof;
34
+ }
35
+
36
+ export interface IBlock extends IBlockCommon {
37
+ transactions?: ITransaction[] | TransactionBase<OPNetTransactionTypes>[];
38
+ }
@@ -0,0 +1,5 @@
1
+ export enum OPNetTransactionTypes {
2
+ Generic = 'Generic',
3
+ Deployment = 'Deployment',
4
+ Interaction = 'Interaction',
5
+ }
@@ -0,0 +1,41 @@
1
+ import { NetEvent } from '@btc-vision/bsi-binary';
2
+ import { BigNumberish } from 'ethers';
3
+ import { ITransactionInput, TransactionInput } from '../../transactions/TransactionInput.js';
4
+ import { ITransactionOutput, TransactionOutput } from '../../transactions/TransactionOutput.js';
5
+ import { OPNetTransactionTypes } from '../opnet/OPNetTransactionTypes.js';
6
+
7
+ export interface ITransactionBase<T extends OPNetTransactionTypes> {
8
+ readonly id: string;
9
+ readonly hash: string;
10
+
11
+ readonly index: number; // Mark the order of the transaction in the block
12
+
13
+ readonly burnedBitcoin: string | BigNumberish;
14
+ readonly revert?: string | Buffer;
15
+
16
+ readonly inputs: ITransactionInput[] | TransactionInput[];
17
+ readonly outputs: ITransactionOutput[] | TransactionOutput[];
18
+
19
+ readonly OPNetType: T;
20
+ }
21
+
22
+ export interface IGenericTransaction extends ITransactionBase<OPNetTransactionTypes.Generic> {}
23
+
24
+ export interface IDeploymentTransaction
25
+ extends ITransactionBase<OPNetTransactionTypes.Deployment> {}
26
+
27
+ export interface IInteractionTransaction
28
+ extends ITransactionBase<OPNetTransactionTypes.Interaction> {
29
+ readonly calldata: string | Buffer;
30
+ readonly senderPubKeyHash: string | Buffer;
31
+ readonly contractSecret: string | Buffer;
32
+ readonly interactionPubKey: string | Buffer;
33
+
34
+ readonly wasCompressed: boolean;
35
+
36
+ readonly events: NetEvent[];
37
+ readonly receipt?: string | Buffer;
38
+ readonly receiptProofs?: string[];
39
+ }
40
+
41
+ export type ITransaction = IDeploymentTransaction | IInteractionTransaction | IGenericTransaction;
@@ -0,0 +1,67 @@
1
+ import { JsonRpcPayload, JsonRpcProvider, JsonRpcResult } from 'ethers';
2
+ import type { BlockTag } from 'ethers/src.ts/providers/provider.js';
3
+ import { Block } from '../block/Block.js';
4
+ import { IBlock } from '../interfaces/blocks/IBlock.js';
5
+
6
+ export class JSONRpcProvider {
7
+ private readonly provider: JsonRpcProvider;
8
+ private readonly url: string;
9
+
10
+ private nextId: number = 0;
11
+
12
+ constructor(url: string) {
13
+ this.url = this.providerUrl(url);
14
+
15
+ this.provider = new JsonRpcProvider(this.url);
16
+ }
17
+
18
+ private providerUrl(url: string): string {
19
+ url = url.trim();
20
+
21
+ if (url.endsWith('/')) {
22
+ return url.slice(0, -1);
23
+ }
24
+
25
+ if (url.includes('api/v1/json-rpc')) {
26
+ return url;
27
+ } else {
28
+ return `${url}/api/v1/json-rpc`;
29
+ }
30
+ }
31
+
32
+ public async getBlockNumber(): Promise<number> {
33
+ return await this.provider.getBlockNumber();
34
+ }
35
+
36
+ public async getBlock(
37
+ blockNumber: BlockTag | string,
38
+ prefetchTxs: boolean = false,
39
+ ): Promise<Block> {
40
+ const method =
41
+ typeof blockNumber === 'string' ? 'btc_getBlockByHash' : 'btc_getBlockByNumber';
42
+
43
+ const payload: JsonRpcPayload = this.buildJsonRpcPayload(method, [
44
+ blockNumber,
45
+ prefetchTxs,
46
+ ]);
47
+
48
+ const blockData: JsonRpcResult[] = await this.provider._send(payload);
49
+ const block = blockData.shift();
50
+
51
+ if (!block) {
52
+ throw new Error('Block not found');
53
+ }
54
+
55
+ const result: IBlock = block.result;
56
+ return new Block(result);
57
+ }
58
+
59
+ private buildJsonRpcPayload(method: string, params: unknown[]): JsonRpcPayload {
60
+ return {
61
+ method: method,
62
+ params: params,
63
+ id: this.nextId++,
64
+ jsonrpc: '2.0',
65
+ };
66
+ }
67
+ }
@@ -0,0 +1,11 @@
1
+ import { JSONRpcProvider } from '../providers/JSONRpcProvider.js';
2
+
3
+ const provider: JSONRpcProvider = new JSONRpcProvider('http://localhost:9001');
4
+
5
+ (async () => {
6
+ const blockNumber = await provider.getBlockNumber();
7
+ console.log('Current network height:', blockNumber);
8
+
9
+ const block = await provider.getBlock(blockNumber, true);
10
+ console.log('Block ->', block);
11
+ })();
@@ -0,0 +1,12 @@
1
+ import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
2
+ import { IDeploymentTransaction } from '../interfaces/transactions/ITransaction.js';
3
+ import { TransactionBase } from './Transaction.js';
4
+
5
+ export class DeploymentTransaction
6
+ extends TransactionBase<OPNetTransactionTypes.Deployment>
7
+ implements IDeploymentTransaction
8
+ {
9
+ constructor(transaction: IDeploymentTransaction) {
10
+ super(transaction);
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
2
+ import { IGenericTransaction } from '../interfaces/transactions/ITransaction.js';
3
+ import { TransactionBase } from './Transaction.js';
4
+
5
+ export class GenericTransaction
6
+ extends TransactionBase<OPNetTransactionTypes.Generic>
7
+ implements IGenericTransaction
8
+ {
9
+ constructor(transaction: IGenericTransaction) {
10
+ super(transaction);
11
+ }
12
+ }
@@ -0,0 +1,39 @@
1
+ import { NetEvent } from '@btc-vision/bsi-binary';
2
+ import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
3
+ import { IInteractionTransaction } from '../interfaces/transactions/ITransaction.js';
4
+ import { TransactionBase } from './Transaction.js';
5
+
6
+ export class InteractionTransaction
7
+ extends TransactionBase<OPNetTransactionTypes.Interaction>
8
+ implements IInteractionTransaction
9
+ {
10
+ public readonly calldata: Buffer;
11
+ public readonly senderPubKeyHash: Buffer;
12
+ public readonly contractSecret: Buffer;
13
+ public readonly interactionPubKey: Buffer;
14
+
15
+ public readonly wasCompressed: boolean;
16
+ public readonly events: NetEvent[];
17
+
18
+ public readonly receipt?: Buffer;
19
+
20
+ public readonly receiptProofs?: string[];
21
+
22
+ constructor(transaction: IInteractionTransaction) {
23
+ super(transaction);
24
+
25
+ this.calldata = Buffer.from(transaction.calldata as string, 'base64');
26
+ this.senderPubKeyHash = Buffer.from(transaction.senderPubKeyHash as string, 'base64');
27
+ this.contractSecret = Buffer.from(transaction.contractSecret as string, 'base64');
28
+ this.interactionPubKey = Buffer.from(transaction.interactionPubKey as string, 'base64');
29
+
30
+ this.wasCompressed = transaction.wasCompressed;
31
+
32
+ this.events = transaction.events;
33
+ this.receipt = transaction.receipt
34
+ ? Buffer.from(transaction.receipt as string, 'base64')
35
+ : undefined;
36
+
37
+ this.receiptProofs = transaction.receiptProofs;
38
+ }
39
+ }
@@ -0,0 +1,42 @@
1
+ import { BigNumberish } from 'ethers';
2
+ import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
3
+ import { ITransactionBase } from '../interfaces/transactions/ITransaction.js';
4
+ import { TransactionInput } from './TransactionInput.js';
5
+ import { ITransactionOutput, TransactionOutput } from './TransactionOutput.js';
6
+
7
+ export abstract class TransactionBase<T extends OPNetTransactionTypes>
8
+ implements ITransactionBase<T>
9
+ {
10
+ public readonly id: string;
11
+ public readonly hash: string;
12
+
13
+ public readonly index: number;
14
+
15
+ public readonly burnedBitcoin: BigNumberish;
16
+ public readonly revert?: Buffer;
17
+
18
+ public readonly inputs: TransactionInput[];
19
+ public readonly outputs: TransactionOutput[];
20
+
21
+ public readonly OPNetType: T;
22
+
23
+ protected constructor(transaction: ITransactionBase<T>) {
24
+ this.id = transaction.id;
25
+ this.hash = transaction.hash;
26
+
27
+ this.index = transaction.index;
28
+
29
+ this.burnedBitcoin = transaction.burnedBitcoin;
30
+
31
+ this.inputs = transaction.inputs.map((input) => new TransactionInput(input));
32
+ this.outputs = transaction.outputs.map(
33
+ (output) => new TransactionOutput(output as ITransactionOutput),
34
+ );
35
+
36
+ this.revert = transaction.revert
37
+ ? Buffer.from(transaction.revert as string, 'base64')
38
+ : undefined;
39
+
40
+ this.OPNetType = transaction.OPNetType;
41
+ }
42
+ }
@@ -0,0 +1,31 @@
1
+ import { ScriptSig } from '@btc-vision/bsi-bitcoin-rpc';
2
+
3
+ export interface ITransactionInput {
4
+ readonly originalTransactionId: string | undefined;
5
+ readonly outputTransactionIndex: number | undefined;
6
+
7
+ readonly scriptSignature: ScriptSig | undefined;
8
+ readonly sequenceId: number;
9
+
10
+ readonly transactionInWitness?: string[];
11
+ }
12
+
13
+ export class TransactionInput implements ITransactionInput {
14
+ public readonly originalTransactionId: string | undefined;
15
+ public readonly outputTransactionIndex: number | undefined;
16
+
17
+ public readonly scriptSignature: ScriptSig | undefined;
18
+ public readonly sequenceId: number;
19
+
20
+ public readonly transactionInWitness: string[] = [];
21
+
22
+ constructor(data: ITransactionInput) {
23
+ this.originalTransactionId = data.originalTransactionId;
24
+ this.outputTransactionIndex = data.outputTransactionIndex;
25
+
26
+ this.scriptSignature = data.scriptSignature;
27
+
28
+ this.sequenceId = data.sequenceId;
29
+ this.transactionInWitness = data.transactionInWitness || [];
30
+ }
31
+ }
@@ -0,0 +1,33 @@
1
+ import { ScriptPubKey } from '@btc-vision/bsi-bitcoin-rpc';
2
+ import { script } from 'bitcoinjs-lib';
3
+
4
+ export interface ITransactionOutput {
5
+ readonly index: number;
6
+ readonly scriptPubKey: {
7
+ hex: string;
8
+ addresses?: string[];
9
+ address?: string;
10
+ };
11
+
12
+ readonly value: string;
13
+ }
14
+
15
+ export class TransactionOutput {
16
+ public readonly value: bigint;
17
+ public readonly index: number;
18
+
19
+ public readonly scriptPubKey: ScriptPubKey;
20
+ public readonly script: Array<number | Buffer> | null;
21
+
22
+ constructor(data: ITransactionOutput) {
23
+ this.value = this.convertValue(data.value);
24
+ this.index = data.index;
25
+
26
+ this.scriptPubKey = data.scriptPubKey;
27
+ this.script = script.decompile(Buffer.from(this.scriptPubKey.hex, 'hex'));
28
+ }
29
+
30
+ private convertValue(value: string): bigint {
31
+ return BigInt(value);
32
+ }
33
+ }
File without changes