@btc-vision/btc-runtime 1.5.1 → 1.5.3
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/README.md +15 -15
- package/package.json +1 -1
- package/runtime/buffer/BytesReader.ts +76 -5
- package/runtime/buffer/BytesWriter.ts +74 -0
- package/runtime/contracts/DeployableOP_20.ts +15 -11
- package/runtime/contracts/OP_NET.ts +4 -7
- package/runtime/env/BlockchainEnvironment.ts +37 -0
- package/runtime/env/classes/UTXO.ts +2 -2
- package/runtime/exports/index.ts +5 -5
- package/runtime/index.ts +12 -9
- package/runtime/memory/{MultiAddressMemoryMap.ts → MapOfMap.ts} +6 -6
- package/runtime/memory/Nested.ts +113 -0
- package/runtime/nested/PointerManager.ts +55 -0
- package/runtime/nested/codecs/AddressCodec.ts +19 -0
- package/runtime/nested/codecs/BooleanCodec.ts +17 -0
- package/runtime/nested/codecs/Ids.ts +10 -0
- package/runtime/nested/codecs/NumericCodec.ts +58 -0
- package/runtime/nested/codecs/StringCodec.ts +24 -0
- package/runtime/nested/codecs/U256Codec.ts +20 -0
- package/runtime/nested/codecs/VariableBytesCodec.ts +134 -0
- package/runtime/nested/interfaces/ICodec.ts +12 -0
- package/runtime/nested/storage/StorageMap.ts +227 -0
- package/runtime/nested/storage/StorageSet.ts +57 -0
- package/runtime/plugins/Plugin.ts +12 -0
- package/runtime/memory/FastUint8Array.ts +0 -122
- package/runtime/memory/MultiStringMemoryMap.ts +0 -65
- package/runtime/memory/StringMemoryMap.ts +0 -56
- package/runtime/memory/Uint8ArrayMerger.ts +0 -72
- package/runtime/storage/Serializable.ts +0 -113
package/README.md
CHANGED
|
@@ -31,13 +31,13 @@ execution while integrating deeply with Bitcoin's decentralized architecture.
|
|
|
31
31
|
|
|
32
32
|
### Features
|
|
33
33
|
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
|
|
37
|
-
-
|
|
38
|
-
|
|
39
|
-
-
|
|
40
|
-
|
|
34
|
+
- **AssemblyScript and WebAssembly:** Efficient and high-performance contract execution using WebAssembly.
|
|
35
|
+
- **Bitcoin Integration:** Direct interaction with Bitcoin L1, enabling the creation of decentralized applications that
|
|
36
|
+
operate on the Bitcoin network.
|
|
37
|
+
- **Comprehensive Storage Management:** Flexible and secure storage management using primary pointers and sub-pointers,
|
|
38
|
+
ensuring data integrity through cryptographic proofs.
|
|
39
|
+
- **Event Handling:** Sophisticated event system for contract state changes, allowing easy tracking and logging of
|
|
40
|
+
contract activities.
|
|
41
41
|
|
|
42
42
|
## Installation
|
|
43
43
|
|
|
@@ -105,7 +105,7 @@ import {
|
|
|
105
105
|
Map,
|
|
106
106
|
OP20InitParameters,
|
|
107
107
|
Selector,
|
|
108
|
-
AddressMap
|
|
108
|
+
AddressMap,
|
|
109
109
|
} from '@btc-vision/btc-runtime/runtime';
|
|
110
110
|
import { u128, u256 } from 'as-bignum/assembly';
|
|
111
111
|
|
|
@@ -142,7 +142,7 @@ export class MyToken extends DeployableOP_20 {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
private airdrop(calldata: Calldata): BytesWriter {
|
|
145
|
-
this.
|
|
145
|
+
this.onlyDeployer(Blockchain.tx.sender);
|
|
146
146
|
|
|
147
147
|
const drops: AddressMap<u256> = calldata.readAddressValueTuple();
|
|
148
148
|
|
|
@@ -169,7 +169,7 @@ export class MyToken extends DeployableOP_20 {
|
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
private airdropWithAmount(calldata: Calldata): BytesWriter {
|
|
172
|
-
this.
|
|
172
|
+
this.onlyDeployer(Blockchain.tx.sender);
|
|
173
173
|
|
|
174
174
|
const amount: u256 = calldata.readU256();
|
|
175
175
|
const addresses: Address[] = calldata.readAddressArray();
|
|
@@ -211,11 +211,11 @@ class ComplexData extends Serializable {
|
|
|
211
211
|
|
|
212
212
|
For more detailed explanations on specific topics, refer to the individual documentation files:
|
|
213
213
|
|
|
214
|
-
-
|
|
215
|
-
-
|
|
216
|
-
-
|
|
217
|
-
-
|
|
218
|
-
-
|
|
214
|
+
- [Blockchain.md](docs/Blockchain.md)
|
|
215
|
+
- [Contract.md](docs/Contract.md)
|
|
216
|
+
- [Events.md](docs/Events.md)
|
|
217
|
+
- [Pointers.md](docs/Pointers.md)
|
|
218
|
+
- [Storage.md](docs/Storage.md)
|
|
219
219
|
|
|
220
220
|
## License
|
|
221
221
|
|
package/package.json
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
U64_BYTE_LENGTH,
|
|
16
16
|
U8_BYTE_LENGTH,
|
|
17
17
|
} from '../utils';
|
|
18
|
+
import { sizeof } from 'builtins';
|
|
18
19
|
|
|
19
20
|
@final
|
|
20
21
|
export class BytesReader {
|
|
@@ -29,6 +30,76 @@ export class BytesReader {
|
|
|
29
30
|
return this.buffer.byteLength;
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
public read<T>(): T {
|
|
34
|
+
const id = idof<T>();
|
|
35
|
+
|
|
36
|
+
if (isBoolean<T>()) {
|
|
37
|
+
return this.readBoolean() as T;
|
|
38
|
+
} else if (isString<T>()) {
|
|
39
|
+
return this.readStringWithLength() as T;
|
|
40
|
+
} else if (isInteger<T>()) {
|
|
41
|
+
if (isSigned<T>()) {
|
|
42
|
+
const size = sizeof<T>();
|
|
43
|
+
|
|
44
|
+
switch (size) {
|
|
45
|
+
case 8:
|
|
46
|
+
return this.readU8() as T;
|
|
47
|
+
case 16:
|
|
48
|
+
return this.readI16() as T;
|
|
49
|
+
case 32:
|
|
50
|
+
return this.readI32() as T;
|
|
51
|
+
case 64:
|
|
52
|
+
return this.readI64() as T;
|
|
53
|
+
default:
|
|
54
|
+
throw new Error(`Invalid size ${size}`);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
const size = sizeof<T>();
|
|
58
|
+
|
|
59
|
+
switch (size) {
|
|
60
|
+
case 8:
|
|
61
|
+
return this.readU8() as T;
|
|
62
|
+
case 16:
|
|
63
|
+
return this.readU16() as T;
|
|
64
|
+
case 32:
|
|
65
|
+
return this.readU32() as T;
|
|
66
|
+
case 64:
|
|
67
|
+
return this.readU64() as T;
|
|
68
|
+
default:
|
|
69
|
+
throw new Error(`Invalid size ${size}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
} else if (id === idof<u256>()) {
|
|
73
|
+
return this.readU256() as T;
|
|
74
|
+
} else if (id === idof<u128>()) {
|
|
75
|
+
return this.readU128() as T;
|
|
76
|
+
} else if (id === idof<i128>()) {
|
|
77
|
+
return this.readI128() as T;
|
|
78
|
+
} else if (id === idof<Address>()) {
|
|
79
|
+
return this.readAddress() as T;
|
|
80
|
+
} else if (id === idof<Uint8Array>()) {
|
|
81
|
+
return this.readBytesWithLength() as T;
|
|
82
|
+
} else if (id === idof<string>()) {
|
|
83
|
+
return this.readStringWithLength() as T;
|
|
84
|
+
} else {
|
|
85
|
+
throw new Error(`Unsupported type ${id}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public readI16(): i16 {
|
|
90
|
+
this.verifyEnd(this.currentOffset + 2);
|
|
91
|
+
const value = this.buffer.getInt16(this.currentOffset, true);
|
|
92
|
+
this.currentOffset += 2;
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public readI32(): i32 {
|
|
97
|
+
this.verifyEnd(this.currentOffset + 4);
|
|
98
|
+
const value = this.buffer.getInt32(this.currentOffset, true);
|
|
99
|
+
this.currentOffset += 4;
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
|
|
32
103
|
public readU8(): u8 {
|
|
33
104
|
this.verifyEnd(this.currentOffset + U8_BYTE_LENGTH);
|
|
34
105
|
const value = this.buffer.getUint8(this.currentOffset);
|
|
@@ -169,7 +240,7 @@ export class BytesReader {
|
|
|
169
240
|
return addr;
|
|
170
241
|
}
|
|
171
242
|
|
|
172
|
-
|
|
243
|
+
// ------------------- Arrays ------------------- //
|
|
173
244
|
|
|
174
245
|
/**
|
|
175
246
|
* The AS writer does `writeU32(length)` for U256 arrays, so we read a u32.
|
|
@@ -258,12 +329,12 @@ export class BytesReader {
|
|
|
258
329
|
}
|
|
259
330
|
|
|
260
331
|
public readTransactionInputs(): TransactionInput[] {
|
|
261
|
-
const length = this.
|
|
332
|
+
const length = this.readU16();
|
|
262
333
|
const result = new Array<TransactionInput>(length);
|
|
263
334
|
|
|
264
335
|
for (let i: u16 = 0; i < length; i++) {
|
|
265
336
|
const txId = this.readBytes(32);
|
|
266
|
-
const outputIndex = this.
|
|
337
|
+
const outputIndex = this.readU16();
|
|
267
338
|
const scriptSig = this.readBytesWithLength();
|
|
268
339
|
result[i] = new TransactionInput(txId, outputIndex, scriptSig);
|
|
269
340
|
}
|
|
@@ -272,11 +343,11 @@ export class BytesReader {
|
|
|
272
343
|
}
|
|
273
344
|
|
|
274
345
|
public readTransactionOutputs(): TransactionOutput[] {
|
|
275
|
-
const length = this.
|
|
346
|
+
const length = this.readU16();
|
|
276
347
|
const result = new Array<TransactionOutput>(length);
|
|
277
348
|
|
|
278
349
|
for (let i: u16 = 0; i < length; i++) {
|
|
279
|
-
const index = this.
|
|
350
|
+
const index = this.readU16();
|
|
280
351
|
const scriptPubKey = this.readStringWithLength();
|
|
281
352
|
const value = this.readU64();
|
|
282
353
|
result[i] = new TransactionOutput(index, scriptPubKey, value);
|
|
@@ -30,6 +30,62 @@ export class BytesWriter {
|
|
|
30
30
|
return this.buffer.byteLength;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
public write<T>(value: T): void {
|
|
34
|
+
if (isInteger<T>()) {
|
|
35
|
+
const size = sizeof<T>();
|
|
36
|
+
if (size === 1) {
|
|
37
|
+
this.writeU8(<u8>value);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (isSigned<T>()) {
|
|
42
|
+
switch (size) {
|
|
43
|
+
case 2:
|
|
44
|
+
this.writeI16(<i16>value);
|
|
45
|
+
break;
|
|
46
|
+
case 4:
|
|
47
|
+
this.writeI32(<i32>value);
|
|
48
|
+
break;
|
|
49
|
+
case 8:
|
|
50
|
+
this.writeI64(<i64>value);
|
|
51
|
+
break;
|
|
52
|
+
default:
|
|
53
|
+
throw new Revert(`Unsupported integer size: ${size}`);
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
switch (size) {
|
|
57
|
+
case 2:
|
|
58
|
+
this.writeU16(<u16>value);
|
|
59
|
+
break;
|
|
60
|
+
case 4:
|
|
61
|
+
this.writeU32(<u32>value);
|
|
62
|
+
break;
|
|
63
|
+
case 8:
|
|
64
|
+
this.writeU64(<u64>value);
|
|
65
|
+
break;
|
|
66
|
+
default:
|
|
67
|
+
throw new Revert(`Unsupported integer size: ${size}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
} else if (isBoolean<T>()) {
|
|
71
|
+
this.writeBoolean(<boolean>value);
|
|
72
|
+
} else if (isString<T>()) {
|
|
73
|
+
this.writeStringWithLength(<string>value);
|
|
74
|
+
} else if (value instanceof Uint8Array) {
|
|
75
|
+
this.writeBytesWithLength(<Uint8Array>value);
|
|
76
|
+
} else if (value instanceof Address) {
|
|
77
|
+
this.writeAddress(<Address>value);
|
|
78
|
+
} else if (value instanceof u128) {
|
|
79
|
+
this.writeU128(<u128>value);
|
|
80
|
+
} else if (value instanceof u256) {
|
|
81
|
+
this.writeU256(<u256>value);
|
|
82
|
+
} else if (value instanceof i128) {
|
|
83
|
+
this.writeI128(<i128>value);
|
|
84
|
+
} else {
|
|
85
|
+
throw new Revert(`Unsupported type: ${typeof value}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
33
89
|
public writeU8(value: u8): void {
|
|
34
90
|
this.allocSafe(U8_BYTE_LENGTH);
|
|
35
91
|
this.buffer.setUint8(this.currentOffset, value);
|
|
@@ -64,6 +120,24 @@ export class BytesWriter {
|
|
|
64
120
|
this.currentOffset += U64_BYTE_LENGTH;
|
|
65
121
|
}
|
|
66
122
|
|
|
123
|
+
public writeI64(value: i64, be: boolean = true): void {
|
|
124
|
+
this.allocSafe(U64_BYTE_LENGTH);
|
|
125
|
+
this.buffer.setInt64(this.currentOffset, value, !be);
|
|
126
|
+
this.currentOffset += U64_BYTE_LENGTH;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
public writeI32(value: i32, be: boolean = true): void {
|
|
130
|
+
this.allocSafe(U32_BYTE_LENGTH);
|
|
131
|
+
this.buffer.setInt32(this.currentOffset, value, !be);
|
|
132
|
+
this.currentOffset += U32_BYTE_LENGTH;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public writeI16(value: i16, be: boolean = true): void {
|
|
136
|
+
this.allocSafe(U16_BYTE_LENGTH);
|
|
137
|
+
this.buffer.setInt16(this.currentOffset, value, !be);
|
|
138
|
+
this.currentOffset += U16_BYTE_LENGTH;
|
|
139
|
+
}
|
|
140
|
+
|
|
67
141
|
/**
|
|
68
142
|
* Writes a 32-bit selector.
|
|
69
143
|
* @param value
|
|
@@ -3,22 +3,22 @@ import { BytesWriter } from '../buffer/BytesWriter';
|
|
|
3
3
|
import { Blockchain } from '../env';
|
|
4
4
|
import { ApproveEvent, BurnEvent, MintEvent, TransferEvent } from '../events/predefined';
|
|
5
5
|
import { encodeSelector, Selector } from '../math/abi';
|
|
6
|
-
import { AddressMemoryMap } from '../memory/AddressMemoryMap';
|
|
7
|
-
import { MultiAddressMemoryMap } from '../memory/MultiAddressMemoryMap';
|
|
8
6
|
import { StoredString } from '../storage/StoredString';
|
|
9
7
|
import { StoredU256 } from '../storage/StoredU256';
|
|
10
8
|
import { Address } from '../types/Address';
|
|
11
9
|
import { Revert } from '../types/Revert';
|
|
12
10
|
import { SafeMath } from '../types/SafeMath';
|
|
13
11
|
|
|
12
|
+
import { sha256 } from '../env/global';
|
|
13
|
+
import { EMPTY_POINTER } from '../math/bytes';
|
|
14
|
+
import { AddressMemoryMap } from '../memory/AddressMemoryMap';
|
|
15
|
+
import { MapOfMap } from '../memory/MapOfMap';
|
|
14
16
|
import { ApproveStr, TransferFromStr, TransferStr } from '../shared-libraries/TransferHelper';
|
|
15
17
|
import { Calldata } from '../types';
|
|
16
18
|
import { ADDRESS_BYTE_LENGTH, BOOLEAN_BYTE_LENGTH, U256_BYTE_LENGTH } from '../utils';
|
|
17
19
|
import { IOP_20 } from './interfaces/IOP_20';
|
|
18
20
|
import { OP20InitParameters } from './interfaces/OP20InitParameters';
|
|
19
21
|
import { OP_NET } from './OP_NET';
|
|
20
|
-
import { sha256 } from '../env/global';
|
|
21
|
-
import { EMPTY_POINTER } from '../math/bytes';
|
|
22
22
|
|
|
23
23
|
const nonceMapPointer: u16 = Blockchain.nextPointer;
|
|
24
24
|
const maxSupplyPointer: u16 = Blockchain.nextPointer;
|
|
@@ -29,7 +29,7 @@ const allowanceMapPointer: u16 = Blockchain.nextPointer;
|
|
|
29
29
|
const balanceOfMapPointer: u16 = Blockchain.nextPointer;
|
|
30
30
|
|
|
31
31
|
export abstract class DeployableOP_20 extends OP_NET implements IOP_20 {
|
|
32
|
-
protected readonly allowanceMap:
|
|
32
|
+
protected readonly allowanceMap: MapOfMap<u256>;
|
|
33
33
|
protected readonly balanceOfMap: AddressMemoryMap;
|
|
34
34
|
|
|
35
35
|
protected readonly _maxSupply: StoredU256;
|
|
@@ -43,14 +43,15 @@ export abstract class DeployableOP_20 extends OP_NET implements IOP_20 {
|
|
|
43
43
|
super();
|
|
44
44
|
|
|
45
45
|
// Initialize main storage structures
|
|
46
|
-
this.allowanceMap = new
|
|
46
|
+
this.allowanceMap = new MapOfMap(allowanceMapPointer);
|
|
47
47
|
this.balanceOfMap = new AddressMemoryMap(balanceOfMapPointer);
|
|
48
|
+
this._nonceMap = new AddressMemoryMap(nonceMapPointer);
|
|
49
|
+
|
|
48
50
|
this._totalSupply = new StoredU256(totalSupplyPointer, EMPTY_POINTER);
|
|
49
51
|
this._maxSupply = new StoredU256(maxSupplyPointer, EMPTY_POINTER);
|
|
50
52
|
this._decimals = new StoredU256(decimalsPointer, EMPTY_POINTER);
|
|
51
53
|
this._name = new StoredString(stringPointer, 0);
|
|
52
54
|
this._symbol = new StoredString(stringPointer, 1);
|
|
53
|
-
this._nonceMap = new AddressMemoryMap(nonceMapPointer);
|
|
54
55
|
|
|
55
56
|
if (params && this._maxSupply.value.isZero()) {
|
|
56
57
|
this.instantiate(params, true);
|
|
@@ -83,12 +84,15 @@ export abstract class DeployableOP_20 extends OP_NET implements IOP_20 {
|
|
|
83
84
|
return this._symbol.value;
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
public instantiate(
|
|
87
|
+
public instantiate(
|
|
88
|
+
params: OP20InitParameters,
|
|
89
|
+
skipDeployerVerification: boolean = false,
|
|
90
|
+
): void {
|
|
87
91
|
if (!this._maxSupply.value.isZero()) {
|
|
88
92
|
throw new Revert('Already initialized');
|
|
89
93
|
}
|
|
90
94
|
|
|
91
|
-
if (!
|
|
95
|
+
if (!skipDeployerVerification) this.onlyDeployer(Blockchain.tx.sender);
|
|
92
96
|
|
|
93
97
|
if (params.decimals > 32) {
|
|
94
98
|
throw new Revert('Decimals can not be more than 32');
|
|
@@ -445,8 +449,8 @@ export abstract class DeployableOP_20 extends OP_NET implements IOP_20 {
|
|
|
445
449
|
this.emitEvent(approveEvent);
|
|
446
450
|
}
|
|
447
451
|
|
|
448
|
-
protected createMintEvent(
|
|
449
|
-
const mintEvent = new MintEvent(
|
|
452
|
+
protected createMintEvent(recipient: Address, value: u256): void {
|
|
453
|
+
const mintEvent = new MintEvent(recipient, value);
|
|
450
454
|
this.emitEvent(mintEvent);
|
|
451
455
|
}
|
|
452
456
|
|
|
@@ -17,14 +17,11 @@ export class OP_NET implements IBTC {
|
|
|
17
17
|
return Blockchain.contractDeployer;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
public onDeployment(_calldata: Calldata): void {
|
|
21
|
-
}
|
|
20
|
+
public onDeployment(_calldata: Calldata): void {}
|
|
22
21
|
|
|
23
|
-
public onExecutionStarted(): void {
|
|
24
|
-
}
|
|
22
|
+
public onExecutionStarted(): void {}
|
|
25
23
|
|
|
26
|
-
public onExecutionCompleted(): void {
|
|
27
|
-
}
|
|
24
|
+
public onExecutionCompleted(): void {}
|
|
28
25
|
|
|
29
26
|
public execute(method: Selector, _calldata: Calldata): BytesWriter {
|
|
30
27
|
let response: BytesWriter;
|
|
@@ -55,7 +52,7 @@ export class OP_NET implements IBTC {
|
|
|
55
52
|
|
|
56
53
|
protected onlyDeployer(caller: Address): void {
|
|
57
54
|
if (this.contractDeployer !== caller) {
|
|
58
|
-
throw new Revert('Only
|
|
55
|
+
throw new Revert('Only deployer can call this method');
|
|
59
56
|
}
|
|
60
57
|
}
|
|
61
58
|
}
|
|
@@ -23,6 +23,8 @@ import {
|
|
|
23
23
|
} from './global';
|
|
24
24
|
import { eqUint, MapUint8Array } from '../generic/MapUint8Array';
|
|
25
25
|
import { EMPTY_BUFFER } from '../math/bytes';
|
|
26
|
+
import { Plugin } from '../plugins/Plugin';
|
|
27
|
+
import { Calldata } from '../types';
|
|
26
28
|
|
|
27
29
|
export * from '../env/global';
|
|
28
30
|
|
|
@@ -38,6 +40,7 @@ export class BlockchainEnvironment {
|
|
|
38
40
|
|
|
39
41
|
private storage: MapUint8Array = new MapUint8Array();
|
|
40
42
|
private _selfContract: Potential<OP_NET> = null;
|
|
43
|
+
private _plugins: Plugin[] = [];
|
|
41
44
|
|
|
42
45
|
private _block: Potential<Block> = null;
|
|
43
46
|
|
|
@@ -105,6 +108,40 @@ export class BlockchainEnvironment {
|
|
|
105
108
|
return this._contractAddress as Address;
|
|
106
109
|
}
|
|
107
110
|
|
|
111
|
+
public registerPlugin(plugin: Plugin): void {
|
|
112
|
+
this._plugins.push(plugin);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public onDeployment(calldata: Calldata): void {
|
|
116
|
+
for (let i: i32 = 0; i < this._plugins.length; i++) {
|
|
117
|
+
const plugin = this._plugins[i];
|
|
118
|
+
|
|
119
|
+
plugin.onDeployment(calldata);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
this.contract.onDeployment(calldata);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public onExecutionStarted(): void {
|
|
126
|
+
for (let i: i32 = 0; i < this._plugins.length; i++) {
|
|
127
|
+
const plugin = this._plugins[i];
|
|
128
|
+
|
|
129
|
+
plugin.onExecutionStarted();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
this.contract.onExecutionStarted();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public onExecutionCompleted(): void {
|
|
136
|
+
for (let i: i32 = 0; i < this._plugins.length; i++) {
|
|
137
|
+
const plugin = this._plugins[i];
|
|
138
|
+
|
|
139
|
+
plugin.onExecutionCompleted();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
this.contract.onExecutionCompleted();
|
|
143
|
+
}
|
|
144
|
+
|
|
108
145
|
public setEnvironmentVariables(data: Uint8Array): void {
|
|
109
146
|
const reader: BytesReader = new BytesReader(data);
|
|
110
147
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export class TransactionInput {
|
|
3
3
|
public constructor(
|
|
4
4
|
public readonly txId: Uint8Array,
|
|
5
|
-
public readonly outputIndex:
|
|
5
|
+
public readonly outputIndex: u16,
|
|
6
6
|
public readonly scriptSig: Uint8Array,
|
|
7
7
|
) {
|
|
8
8
|
}
|
|
@@ -11,7 +11,7 @@ export class TransactionInput {
|
|
|
11
11
|
@final
|
|
12
12
|
export class TransactionOutput {
|
|
13
13
|
public constructor(
|
|
14
|
-
public readonly index:
|
|
14
|
+
public readonly index: u16,
|
|
15
15
|
public readonly to: string,
|
|
16
16
|
public readonly value: u64,
|
|
17
17
|
) {
|
package/runtime/exports/index.ts
CHANGED
|
@@ -18,11 +18,11 @@ export function execute(calldataLength: u32): u32 {
|
|
|
18
18
|
const calldata: Calldata = new BytesReader(Uint8Array.wrap(calldataBuffer));
|
|
19
19
|
const selector: Selector = calldata.readSelector();
|
|
20
20
|
|
|
21
|
-
Blockchain.
|
|
21
|
+
Blockchain.onExecutionStarted();
|
|
22
22
|
|
|
23
23
|
const result: BytesWriter = Blockchain.contract.execute(selector, calldata);
|
|
24
24
|
|
|
25
|
-
Blockchain.
|
|
25
|
+
Blockchain.onExecutionCompleted();
|
|
26
26
|
|
|
27
27
|
const resultBuffer = result.getBuffer().buffer;
|
|
28
28
|
const resultLength = resultBuffer.byteLength;
|
|
@@ -43,9 +43,9 @@ export function onDeploy(calldataLength: u32): u32 {
|
|
|
43
43
|
|
|
44
44
|
const calldata: Calldata = new BytesReader(Uint8Array.wrap(calldataBuffer));
|
|
45
45
|
|
|
46
|
-
Blockchain.
|
|
47
|
-
Blockchain.
|
|
48
|
-
Blockchain.
|
|
46
|
+
Blockchain.onExecutionStarted();
|
|
47
|
+
Blockchain.onDeployment(calldata);
|
|
48
|
+
Blockchain.onExecutionCompleted();
|
|
49
49
|
|
|
50
50
|
return 0;
|
|
51
51
|
}
|
package/runtime/index.ts
CHANGED
|
@@ -45,12 +45,18 @@ export * from './math/bytes';
|
|
|
45
45
|
export * from './secp256k1/ECPoint';
|
|
46
46
|
|
|
47
47
|
/** Memory */
|
|
48
|
-
export * from './memory/
|
|
49
|
-
export * from './
|
|
50
|
-
export * from './
|
|
51
|
-
export * from './
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
export * from './memory/Nested';
|
|
49
|
+
export * from './nested/PointerManager';
|
|
50
|
+
export * from './nested/storage/StorageMap';
|
|
51
|
+
export * from './nested/storage/StorageSet';
|
|
52
|
+
|
|
53
|
+
/** Codecs */
|
|
54
|
+
export * from './nested/codecs/U256Codec';
|
|
55
|
+
export * from './nested/codecs/AddressCodec';
|
|
56
|
+
export * from './nested/codecs/NumericCodec';
|
|
57
|
+
export * from './nested/codecs/BooleanCodec';
|
|
58
|
+
export * from './nested/codecs/StringCodec';
|
|
59
|
+
export * from './nested/codecs/VariableBytesCodec';
|
|
54
60
|
|
|
55
61
|
/** Storage */
|
|
56
62
|
export * from './storage/StoredU256';
|
|
@@ -58,7 +64,6 @@ export * from './storage/StoredU64';
|
|
|
58
64
|
export * from './storage/StoredString';
|
|
59
65
|
export * from './storage/StoredAddress';
|
|
60
66
|
export * from './storage/StoredBoolean';
|
|
61
|
-
export * from './storage/Serializable';
|
|
62
67
|
|
|
63
68
|
/** Arrays */
|
|
64
69
|
export * from './storage/arrays/StoredAddressArray';
|
|
@@ -71,8 +76,6 @@ export * from './storage/arrays/StoredU64Array';
|
|
|
71
76
|
export * from './storage/arrays/StoredU128Array';
|
|
72
77
|
export * from './storage/arrays/StoredU256Array';
|
|
73
78
|
|
|
74
|
-
export * from './memory/FastUint8Array';
|
|
75
|
-
|
|
76
79
|
/** Shared libraries */
|
|
77
80
|
export * from './shared-libraries/TransferHelper';
|
|
78
81
|
export * from './shared-libraries/OP20Utils';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Uint8ArrayMerger } from './Uint8ArrayMerger';
|
|
2
1
|
import { Address } from '../types/Address';
|
|
2
|
+
import { Nested } from './Nested';
|
|
3
3
|
|
|
4
4
|
@final
|
|
5
|
-
export class
|
|
5
|
+
export class MapOfMap<T> extends Map<
|
|
6
6
|
Address,
|
|
7
|
-
|
|
7
|
+
Nested<T>
|
|
8
8
|
> {
|
|
9
9
|
public pointer: u16;
|
|
10
10
|
|
|
@@ -17,14 +17,14 @@ export class MultiAddressMemoryMap extends Map<
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
@inline
|
|
20
|
-
public get(key: Address):
|
|
20
|
+
public get(key: Address): Nested<T> {
|
|
21
21
|
this.createKeyMerger(key);
|
|
22
22
|
|
|
23
23
|
return super.get(key);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
@inline
|
|
27
|
-
public set(key: Address, value:
|
|
27
|
+
public set(key: Address, value: Nested<T>): this {
|
|
28
28
|
this.createKeyMerger(key);
|
|
29
29
|
|
|
30
30
|
return <this>super.set(key, value);
|
|
@@ -48,7 +48,7 @@ export class MultiAddressMemoryMap extends Map<
|
|
|
48
48
|
@inline
|
|
49
49
|
private createKeyMerger(key: Address): void {
|
|
50
50
|
if (!super.has(key)) {
|
|
51
|
-
super.set(key, new
|
|
51
|
+
super.set(key, new Nested<T>(key, this.pointer));
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|