koilib 5.4.0 → 5.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/koinos.js +15450 -2546
- package/dist/koinos.min.js +1 -1
- package/lib/Contract.d.ts +45 -1
- package/lib/Contract.js +156 -77
- package/lib/Contract.js.map +1 -1
- package/lib/Serializer.d.ts +36 -15
- package/lib/Serializer.js +82 -16
- package/lib/Serializer.js.map +1 -1
- package/lib/Transaction.js +1 -1
- package/lib/Transaction.js.map +1 -1
- package/lib/browser/Contract.d.ts +45 -1
- package/lib/browser/Contract.js +156 -77
- package/lib/browser/Contract.js.map +1 -1
- package/lib/browser/Serializer.d.ts +36 -15
- package/lib/browser/Serializer.js +82 -16
- package/lib/browser/Serializer.js.map +1 -1
- package/lib/browser/Transaction.js +1 -1
- package/lib/browser/Transaction.js.map +1 -1
- package/lib/browser/interface.d.ts +130 -14
- package/lib/interface.d.ts +130 -14
- package/package.json +3 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../src/Transaction.ts"],"names":[],"mappings":";;;AAEA,qCAAkC;AAWlC,MAAa,WAAW;IA0BtB,YAAY,CAIX;;QACC,IAAI,CAAC,MAAM,GAAG,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,MAAM,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,QAAQ,CAAC;QAC5B,IAAI,CAAC,OAAO,GAAG;YACb,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,IAAI;YACd,GAAG,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,OAAO;SACd,CAAC;QACF,IAAI,CAAC,WAAW,GAAG;YACjB,MAAM,EAAE;gBACN,GAAG,CAAC,CAAA,MAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,OAAO,0CAAE,OAAO,KAAI,EAAE,QAAQ,EAAE,CAAC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ACf,CAAC;QACF,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC,IAAI,CAAC;QAC5B,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,IAAI,CACR,IAAoC,EACpC,OAAgB;QAKhB,IAAI,CAAC,IAAI,CAAC,YAAY;YAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;CACF;AAnOD,kCAmOC"}
|
|
@@ -3,11 +3,15 @@ import { Serializer } from "./Serializer";
|
|
|
3
3
|
/**
|
|
4
4
|
* Application Binary Interface (ABI)
|
|
5
5
|
*
|
|
6
|
-
* ABIs are composed of
|
|
6
|
+
* ABIs are composed of 3 elements: methods, events, and types.
|
|
7
7
|
* - The methods define the names of the entries of the smart contract,
|
|
8
8
|
* the corresponding endpoints and the name of the types used.
|
|
9
|
-
* - The
|
|
10
|
-
*
|
|
9
|
+
* - The events define possible events triggered by the smart contract
|
|
10
|
+
* and the name of the types used.
|
|
11
|
+
* - The types contain the description to serialize and deserialize
|
|
12
|
+
* data using proto buffers. It is used to encode/decode the methods
|
|
13
|
+
* and events. These types can be provided in binary format or json
|
|
14
|
+
* format (koilib_types)
|
|
11
15
|
*
|
|
12
16
|
* To generate the types is necessary to use the dependency
|
|
13
17
|
* protobufjs. The following example shows how to generate the
|
|
@@ -49,7 +53,12 @@ import { Serializer } from "./Serializer";
|
|
|
49
53
|
* return: "mint_result",
|
|
50
54
|
* },
|
|
51
55
|
* },
|
|
52
|
-
*
|
|
56
|
+
* events: {
|
|
57
|
+
* 'koinos.contracts.token.mint_event': {
|
|
58
|
+
* argument: "mint"
|
|
59
|
+
* },
|
|
60
|
+
* },
|
|
61
|
+
* koilib_types: tokenJson,
|
|
53
62
|
* };
|
|
54
63
|
* ```
|
|
55
64
|
*
|
|
@@ -58,6 +67,95 @@ import { Serializer } from "./Serializer";
|
|
|
58
67
|
* empty response (for instance when there are no balance records
|
|
59
68
|
* for a specific address) and you require a default output in
|
|
60
69
|
* such cases.
|
|
70
|
+
*
|
|
71
|
+
* **Definition of events**
|
|
72
|
+
*
|
|
73
|
+
* There are 2 ways to define events in koinos:
|
|
74
|
+
* - Event names as protobuffer names
|
|
75
|
+
* - Custom event names
|
|
76
|
+
*
|
|
77
|
+
* 1. Event names as protobuffer names: The name of the event links
|
|
78
|
+
* with the protobuffer definition. In this case there is no need
|
|
79
|
+
* to define the event in the ABI.
|
|
80
|
+
*
|
|
81
|
+
* Example:
|
|
82
|
+
*
|
|
83
|
+
* Proto definition
|
|
84
|
+
* ```
|
|
85
|
+
* package koinos.contracts.token;
|
|
86
|
+
*
|
|
87
|
+
* message transfer_arguments {
|
|
88
|
+
* bytes from = 1 [(btype) = ADDRESS];
|
|
89
|
+
* bytes to = 2 [(btype) = ADDRESS];
|
|
90
|
+
* uint64 value = 3 [jstype = JS_STRING];
|
|
91
|
+
* }
|
|
92
|
+
*
|
|
93
|
+
* message transfer_event {
|
|
94
|
+
* bytes from = 1 [(btype) = ADDRESS];
|
|
95
|
+
* bytes to = 2 [(btype) = ADDRESS];
|
|
96
|
+
* uint64 value = 3 [jstype = JS_STRING];
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* Contract
|
|
101
|
+
* ```ts
|
|
102
|
+
* // token-contract.ts
|
|
103
|
+
* transfer(args: token.transfer_arguments): token.transfer_result {
|
|
104
|
+
* ...
|
|
105
|
+
* System.event("koinos.contracts.token.transfer_event", Protobuf.encode(event, token.transfer_event.encode), impacted);
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* 2. Custom event names: The previous definition has a limitation. It's
|
|
110
|
+
* necessary to define a proto message for each event and argument, and they can
|
|
111
|
+
* not be reused. In this second solution, the event names are defined
|
|
112
|
+
* in the ABI and they are linked with the corresponding protobuffer definitions.
|
|
113
|
+
* In this sense, they can be reused.
|
|
114
|
+
*
|
|
115
|
+
* Example
|
|
116
|
+
*
|
|
117
|
+
* Proto definition
|
|
118
|
+
* ```
|
|
119
|
+
* package koinos.contracts.token;
|
|
120
|
+
*
|
|
121
|
+
* // only 1 message
|
|
122
|
+
* message transfer {
|
|
123
|
+
* bytes from = 1 [(btype) = ADDRESS];
|
|
124
|
+
* bytes to = 2 [(btype) = ADDRESS];
|
|
125
|
+
* uint64 value = 3 [jstype = JS_STRING];
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* Contract
|
|
130
|
+
* ```ts
|
|
131
|
+
* // token-contract.ts
|
|
132
|
+
*
|
|
133
|
+
* // Transfer of tokens
|
|
134
|
+
* // @event transfer_event token.transfer
|
|
135
|
+
* transfer(args: token.transfer): void {
|
|
136
|
+
* ...
|
|
137
|
+
* System.event("transfer_event", Protobuf.encode(event, token.transfer.encode), impacted);
|
|
138
|
+
* }
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* ABI
|
|
142
|
+
* ```ts
|
|
143
|
+
* const abiToken = {
|
|
144
|
+
* methods: {
|
|
145
|
+
* transfer: {
|
|
146
|
+
* entry_point: 0x62efa292,
|
|
147
|
+
* argument: "transfer",
|
|
148
|
+
* return: "",
|
|
149
|
+
* },
|
|
150
|
+
* },
|
|
151
|
+
* events: {
|
|
152
|
+
* 'transfer_event': {
|
|
153
|
+
* argument: "transfer"
|
|
154
|
+
* },
|
|
155
|
+
* },
|
|
156
|
+
* koilib_types: tokenJson,
|
|
157
|
+
* };
|
|
158
|
+
* ```
|
|
61
159
|
*/
|
|
62
160
|
export interface Abi {
|
|
63
161
|
methods: {
|
|
@@ -84,11 +182,26 @@ export interface Abi {
|
|
|
84
182
|
description?: string;
|
|
85
183
|
};
|
|
86
184
|
};
|
|
185
|
+
/**
|
|
186
|
+
* Protobuffers descriptor in binary format encoded in base64url.
|
|
187
|
+
*/
|
|
188
|
+
types?: string;
|
|
87
189
|
/**
|
|
88
190
|
* Protobuffers descriptor in JSON format.
|
|
89
191
|
* See https://www.npmjs.com/package/protobufjs#using-json-descriptors
|
|
90
192
|
*/
|
|
91
|
-
koilib_types
|
|
193
|
+
koilib_types?: INamespace;
|
|
194
|
+
/**
|
|
195
|
+
* Definition of events
|
|
196
|
+
*/
|
|
197
|
+
events?: {
|
|
198
|
+
[x: string]: {
|
|
199
|
+
/** Protobuffer type for argument */
|
|
200
|
+
argument?: string;
|
|
201
|
+
/** Description of the event */
|
|
202
|
+
description?: string;
|
|
203
|
+
};
|
|
204
|
+
};
|
|
92
205
|
}
|
|
93
206
|
/**
|
|
94
207
|
* Human readable format operation
|
|
@@ -252,8 +365,7 @@ export interface ContractTransactionOptions extends TransactionOptions {
|
|
|
252
365
|
*/
|
|
253
366
|
sendTransaction?: boolean;
|
|
254
367
|
}
|
|
255
|
-
export
|
|
256
|
-
}
|
|
368
|
+
export declare type CallContractOptions = ContractTransactionOptions;
|
|
257
369
|
export interface DeployOptions extends ContractTransactionOptions {
|
|
258
370
|
/**
|
|
259
371
|
* ABI
|
|
@@ -525,6 +637,16 @@ export interface ValueType {
|
|
|
525
637
|
uint64_value?: string;
|
|
526
638
|
[x: string]: unknown;
|
|
527
639
|
}
|
|
640
|
+
export interface EventData {
|
|
641
|
+
sequence: number;
|
|
642
|
+
source: string;
|
|
643
|
+
name: string;
|
|
644
|
+
data: string;
|
|
645
|
+
impacted: string[];
|
|
646
|
+
}
|
|
647
|
+
export interface DecodedEventData extends EventData {
|
|
648
|
+
args: Record<string, unknown>;
|
|
649
|
+
}
|
|
528
650
|
export interface TransactionReceipt {
|
|
529
651
|
id: string;
|
|
530
652
|
payer: string;
|
|
@@ -535,12 +657,6 @@ export interface TransactionReceipt {
|
|
|
535
657
|
network_bandwidth_used: string;
|
|
536
658
|
compute_bandwidth_used: string;
|
|
537
659
|
reverted: boolean;
|
|
538
|
-
events:
|
|
539
|
-
sequence: number;
|
|
540
|
-
source: string;
|
|
541
|
-
name: string;
|
|
542
|
-
data: string;
|
|
543
|
-
impacted: string[];
|
|
544
|
-
}[];
|
|
660
|
+
events: EventData[];
|
|
545
661
|
logs: string[];
|
|
546
662
|
}
|
package/lib/interface.d.ts
CHANGED
|
@@ -3,11 +3,15 @@ import { Serializer } from "./Serializer";
|
|
|
3
3
|
/**
|
|
4
4
|
* Application Binary Interface (ABI)
|
|
5
5
|
*
|
|
6
|
-
* ABIs are composed of
|
|
6
|
+
* ABIs are composed of 3 elements: methods, events, and types.
|
|
7
7
|
* - The methods define the names of the entries of the smart contract,
|
|
8
8
|
* the corresponding endpoints and the name of the types used.
|
|
9
|
-
* - The
|
|
10
|
-
*
|
|
9
|
+
* - The events define possible events triggered by the smart contract
|
|
10
|
+
* and the name of the types used.
|
|
11
|
+
* - The types contain the description to serialize and deserialize
|
|
12
|
+
* data using proto buffers. It is used to encode/decode the methods
|
|
13
|
+
* and events. These types can be provided in binary format or json
|
|
14
|
+
* format (koilib_types)
|
|
11
15
|
*
|
|
12
16
|
* To generate the types is necessary to use the dependency
|
|
13
17
|
* protobufjs. The following example shows how to generate the
|
|
@@ -49,7 +53,12 @@ import { Serializer } from "./Serializer";
|
|
|
49
53
|
* return: "mint_result",
|
|
50
54
|
* },
|
|
51
55
|
* },
|
|
52
|
-
*
|
|
56
|
+
* events: {
|
|
57
|
+
* 'koinos.contracts.token.mint_event': {
|
|
58
|
+
* argument: "mint"
|
|
59
|
+
* },
|
|
60
|
+
* },
|
|
61
|
+
* koilib_types: tokenJson,
|
|
53
62
|
* };
|
|
54
63
|
* ```
|
|
55
64
|
*
|
|
@@ -58,6 +67,95 @@ import { Serializer } from "./Serializer";
|
|
|
58
67
|
* empty response (for instance when there are no balance records
|
|
59
68
|
* for a specific address) and you require a default output in
|
|
60
69
|
* such cases.
|
|
70
|
+
*
|
|
71
|
+
* **Definition of events**
|
|
72
|
+
*
|
|
73
|
+
* There are 2 ways to define events in koinos:
|
|
74
|
+
* - Event names as protobuffer names
|
|
75
|
+
* - Custom event names
|
|
76
|
+
*
|
|
77
|
+
* 1. Event names as protobuffer names: The name of the event links
|
|
78
|
+
* with the protobuffer definition. In this case there is no need
|
|
79
|
+
* to define the event in the ABI.
|
|
80
|
+
*
|
|
81
|
+
* Example:
|
|
82
|
+
*
|
|
83
|
+
* Proto definition
|
|
84
|
+
* ```
|
|
85
|
+
* package koinos.contracts.token;
|
|
86
|
+
*
|
|
87
|
+
* message transfer_arguments {
|
|
88
|
+
* bytes from = 1 [(btype) = ADDRESS];
|
|
89
|
+
* bytes to = 2 [(btype) = ADDRESS];
|
|
90
|
+
* uint64 value = 3 [jstype = JS_STRING];
|
|
91
|
+
* }
|
|
92
|
+
*
|
|
93
|
+
* message transfer_event {
|
|
94
|
+
* bytes from = 1 [(btype) = ADDRESS];
|
|
95
|
+
* bytes to = 2 [(btype) = ADDRESS];
|
|
96
|
+
* uint64 value = 3 [jstype = JS_STRING];
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* Contract
|
|
101
|
+
* ```ts
|
|
102
|
+
* // token-contract.ts
|
|
103
|
+
* transfer(args: token.transfer_arguments): token.transfer_result {
|
|
104
|
+
* ...
|
|
105
|
+
* System.event("koinos.contracts.token.transfer_event", Protobuf.encode(event, token.transfer_event.encode), impacted);
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* 2. Custom event names: The previous definition has a limitation. It's
|
|
110
|
+
* necessary to define a proto message for each event and argument, and they can
|
|
111
|
+
* not be reused. In this second solution, the event names are defined
|
|
112
|
+
* in the ABI and they are linked with the corresponding protobuffer definitions.
|
|
113
|
+
* In this sense, they can be reused.
|
|
114
|
+
*
|
|
115
|
+
* Example
|
|
116
|
+
*
|
|
117
|
+
* Proto definition
|
|
118
|
+
* ```
|
|
119
|
+
* package koinos.contracts.token;
|
|
120
|
+
*
|
|
121
|
+
* // only 1 message
|
|
122
|
+
* message transfer {
|
|
123
|
+
* bytes from = 1 [(btype) = ADDRESS];
|
|
124
|
+
* bytes to = 2 [(btype) = ADDRESS];
|
|
125
|
+
* uint64 value = 3 [jstype = JS_STRING];
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* Contract
|
|
130
|
+
* ```ts
|
|
131
|
+
* // token-contract.ts
|
|
132
|
+
*
|
|
133
|
+
* // Transfer of tokens
|
|
134
|
+
* // @event transfer_event token.transfer
|
|
135
|
+
* transfer(args: token.transfer): void {
|
|
136
|
+
* ...
|
|
137
|
+
* System.event("transfer_event", Protobuf.encode(event, token.transfer.encode), impacted);
|
|
138
|
+
* }
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* ABI
|
|
142
|
+
* ```ts
|
|
143
|
+
* const abiToken = {
|
|
144
|
+
* methods: {
|
|
145
|
+
* transfer: {
|
|
146
|
+
* entry_point: 0x62efa292,
|
|
147
|
+
* argument: "transfer",
|
|
148
|
+
* return: "",
|
|
149
|
+
* },
|
|
150
|
+
* },
|
|
151
|
+
* events: {
|
|
152
|
+
* 'transfer_event': {
|
|
153
|
+
* argument: "transfer"
|
|
154
|
+
* },
|
|
155
|
+
* },
|
|
156
|
+
* koilib_types: tokenJson,
|
|
157
|
+
* };
|
|
158
|
+
* ```
|
|
61
159
|
*/
|
|
62
160
|
export interface Abi {
|
|
63
161
|
methods: {
|
|
@@ -84,11 +182,26 @@ export interface Abi {
|
|
|
84
182
|
description?: string;
|
|
85
183
|
};
|
|
86
184
|
};
|
|
185
|
+
/**
|
|
186
|
+
* Protobuffers descriptor in binary format encoded in base64url.
|
|
187
|
+
*/
|
|
188
|
+
types?: string;
|
|
87
189
|
/**
|
|
88
190
|
* Protobuffers descriptor in JSON format.
|
|
89
191
|
* See https://www.npmjs.com/package/protobufjs#using-json-descriptors
|
|
90
192
|
*/
|
|
91
|
-
koilib_types
|
|
193
|
+
koilib_types?: INamespace;
|
|
194
|
+
/**
|
|
195
|
+
* Definition of events
|
|
196
|
+
*/
|
|
197
|
+
events?: {
|
|
198
|
+
[x: string]: {
|
|
199
|
+
/** Protobuffer type for argument */
|
|
200
|
+
argument?: string;
|
|
201
|
+
/** Description of the event */
|
|
202
|
+
description?: string;
|
|
203
|
+
};
|
|
204
|
+
};
|
|
92
205
|
}
|
|
93
206
|
/**
|
|
94
207
|
* Human readable format operation
|
|
@@ -252,8 +365,7 @@ export interface ContractTransactionOptions extends TransactionOptions {
|
|
|
252
365
|
*/
|
|
253
366
|
sendTransaction?: boolean;
|
|
254
367
|
}
|
|
255
|
-
export
|
|
256
|
-
}
|
|
368
|
+
export declare type CallContractOptions = ContractTransactionOptions;
|
|
257
369
|
export interface DeployOptions extends ContractTransactionOptions {
|
|
258
370
|
/**
|
|
259
371
|
* ABI
|
|
@@ -525,6 +637,16 @@ export interface ValueType {
|
|
|
525
637
|
uint64_value?: string;
|
|
526
638
|
[x: string]: unknown;
|
|
527
639
|
}
|
|
640
|
+
export interface EventData {
|
|
641
|
+
sequence: number;
|
|
642
|
+
source: string;
|
|
643
|
+
name: string;
|
|
644
|
+
data: string;
|
|
645
|
+
impacted: string[];
|
|
646
|
+
}
|
|
647
|
+
export interface DecodedEventData extends EventData {
|
|
648
|
+
args: Record<string, unknown>;
|
|
649
|
+
}
|
|
528
650
|
export interface TransactionReceipt {
|
|
529
651
|
id: string;
|
|
530
652
|
payer: string;
|
|
@@ -535,12 +657,6 @@ export interface TransactionReceipt {
|
|
|
535
657
|
network_bandwidth_used: string;
|
|
536
658
|
compute_bandwidth_used: string;
|
|
537
659
|
reverted: boolean;
|
|
538
|
-
events:
|
|
539
|
-
sequence: number;
|
|
540
|
-
source: string;
|
|
541
|
-
name: string;
|
|
542
|
-
data: string;
|
|
543
|
-
impacted: string[];
|
|
544
|
-
}[];
|
|
660
|
+
events: EventData[];
|
|
545
661
|
logs: string[];
|
|
546
662
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koilib",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.0",
|
|
4
4
|
"description": "JS Koinos Library",
|
|
5
5
|
"author": "Julian Gonzalez",
|
|
6
6
|
"repository": {
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@noble/hashes": "^1.1.2",
|
|
48
48
|
"@noble/secp256k1": "^1.6.3",
|
|
49
|
+
"@roamin/koinos-pb-to-proto": "^0.0.2",
|
|
49
50
|
"cross-fetch": "^3.1.5",
|
|
50
51
|
"multibase": "^4.0.6",
|
|
51
52
|
"protobufjs": "^7.0.0"
|
|
@@ -76,6 +77,7 @@
|
|
|
76
77
|
"rimraf": "^3.0.2",
|
|
77
78
|
"ts-jest": "^28.0.8",
|
|
78
79
|
"ts-loader": "^9.3.1",
|
|
80
|
+
"ts-node": "^10.9.1",
|
|
79
81
|
"typedoc": "^0.23.10",
|
|
80
82
|
"typescript": "^4.7.4",
|
|
81
83
|
"webpack": "^5.74.0",
|