@btc-vision/btc-runtime 1.0.30 → 1.1.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/package.json +1 -1
- package/runtime/buffer/BytesReader.ts +200 -200
- package/runtime/buffer/BytesWriter.ts +346 -346
- package/runtime/contracts/DeployableOP_20.ts +409 -0
- package/runtime/contracts/OP_20.ts +8 -341
- package/runtime/contracts/OP_NET.ts +73 -73
- package/runtime/contracts/interfaces/IOP_20.ts +21 -21
- package/runtime/env/BTCEnvironment.ts +319 -319
- package/runtime/env/index.ts +3 -3
- package/runtime/events/NetEvent.ts +27 -27
- package/runtime/events/predefined/ApproveEvent.ts +16 -16
- package/runtime/events/predefined/BurnEvent.ts +13 -13
- package/runtime/events/predefined/ClaimEvent.ts +13 -13
- package/runtime/events/predefined/MintEvent.ts +15 -15
- package/runtime/events/predefined/StakeEvent.ts +13 -13
- package/runtime/events/predefined/TransferEvent.ts +16 -16
- package/runtime/events/predefined/UnstakeEvent.ts +13 -13
- package/runtime/events/predefined/index.ts +7 -7
- package/runtime/exports/index.ts +37 -37
- package/runtime/generic/Map.ts +65 -65
- package/runtime/generic/MapU256.ts +57 -57
- package/runtime/index.ts +56 -53
- package/runtime/interfaces/DeployContractResponse.ts +12 -12
- package/runtime/interfaces/IBTC.ts +6 -6
- package/runtime/lang/Definitions.ts +1 -1
- package/runtime/math/abi.ts +37 -37
- package/runtime/math/bytes.ts +34 -34
- package/runtime/math/cyrb53.ts +46 -46
- package/runtime/math/rnd.ts +51 -51
- package/runtime/math/sha256.ts +12 -12
- package/runtime/memory/AddressMemoryMap.ts +44 -44
- package/runtime/memory/KeyMerger.ts +53 -53
- package/runtime/memory/MemorySlot.ts +1 -1
- package/runtime/memory/MemorySlotPointer.ts +3 -3
- package/runtime/memory/MultiAddressMemoryMap.ts +62 -62
- package/runtime/shared-libraries/OP20Utils.ts +21 -0
- package/runtime/shared-libraries/TransferHelper.ts +64 -64
- package/runtime/storage/Serializable.ts +6 -2
- package/runtime/storage/StoredBoolean.ts +48 -0
- package/runtime/storage/StoredString.ts +145 -145
- package/runtime/storage/StoredU256.ts +248 -246
- package/runtime/types/Address.ts +5 -5
- package/runtime/types/Revert.ts +5 -5
- package/runtime/types/SafeMath.ts +197 -197
- package/runtime/types/index.ts +8 -8
- package/runtime/universal/ABIRegistry.ts +72 -72
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { MemorySlotData } from './MemorySlot';
|
|
2
|
-
import { u256 } from 'as-bignum/assembly';
|
|
3
|
-
import { Blockchain } from '../env';
|
|
4
|
-
import { MemorySlotPointer } from './MemorySlotPointer';
|
|
5
|
-
import { encodePointer } from '../math/abi';
|
|
6
|
-
|
|
7
|
-
@final
|
|
8
|
-
export class KeyMerger<K extends string, K2 extends string, V extends MemorySlotData<u256>> {
|
|
9
|
-
public parentKey: K;
|
|
10
|
-
|
|
11
|
-
public pointer: u16;
|
|
12
|
-
|
|
13
|
-
constructor(
|
|
14
|
-
parent: K,
|
|
15
|
-
pointer: u16,
|
|
16
|
-
private readonly defaultValue: V,
|
|
17
|
-
) {
|
|
18
|
-
this.pointer = pointer;
|
|
19
|
-
|
|
20
|
-
this.parentKey = parent;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public set(key2: K2, value: V): this {
|
|
24
|
-
const mergedKey: string = `${this.parentKey}${key2}`;
|
|
25
|
-
const keyHash: MemorySlotPointer = encodePointer(mergedKey);
|
|
26
|
-
|
|
27
|
-
Blockchain.setStorageAt(this.pointer, keyHash, value);
|
|
28
|
-
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public get(key: K): MemorySlotData<u256> {
|
|
33
|
-
const mergedKey: string = `${this.parentKey}${key}`;
|
|
34
|
-
|
|
35
|
-
return Blockchain.getStorageAt(this.pointer, encodePointer(mergedKey), this.defaultValue);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public has(key: K): bool {
|
|
39
|
-
const mergedKey: string = `${this.parentKey}${key}`;
|
|
40
|
-
|
|
41
|
-
return Blockchain.hasStorageAt(this.pointer, encodePointer(mergedKey));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
@unsafe
|
|
45
|
-
public delete(_key: K): bool {
|
|
46
|
-
throw new Error('Method not implemented.');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@unsafe
|
|
50
|
-
public clear(): void {
|
|
51
|
-
throw new Error('Clear method not implemented.');
|
|
52
|
-
}
|
|
53
|
-
}
|
|
1
|
+
import { MemorySlotData } from './MemorySlot';
|
|
2
|
+
import { u256 } from 'as-bignum/assembly';
|
|
3
|
+
import { Blockchain } from '../env';
|
|
4
|
+
import { MemorySlotPointer } from './MemorySlotPointer';
|
|
5
|
+
import { encodePointer } from '../math/abi';
|
|
6
|
+
|
|
7
|
+
@final
|
|
8
|
+
export class KeyMerger<K extends string, K2 extends string, V extends MemorySlotData<u256>> {
|
|
9
|
+
public parentKey: K;
|
|
10
|
+
|
|
11
|
+
public pointer: u16;
|
|
12
|
+
|
|
13
|
+
constructor(
|
|
14
|
+
parent: K,
|
|
15
|
+
pointer: u16,
|
|
16
|
+
private readonly defaultValue: V,
|
|
17
|
+
) {
|
|
18
|
+
this.pointer = pointer;
|
|
19
|
+
|
|
20
|
+
this.parentKey = parent;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public set(key2: K2, value: V): this {
|
|
24
|
+
const mergedKey: string = `${this.parentKey}${key2}`;
|
|
25
|
+
const keyHash: MemorySlotPointer = encodePointer(mergedKey);
|
|
26
|
+
|
|
27
|
+
Blockchain.setStorageAt(this.pointer, keyHash, value);
|
|
28
|
+
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public get(key: K): MemorySlotData<u256> {
|
|
33
|
+
const mergedKey: string = `${this.parentKey}${key}`;
|
|
34
|
+
|
|
35
|
+
return Blockchain.getStorageAt(this.pointer, encodePointer(mergedKey), this.defaultValue);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public has(key: K): bool {
|
|
39
|
+
const mergedKey: string = `${this.parentKey}${key}`;
|
|
40
|
+
|
|
41
|
+
return Blockchain.hasStorageAt(this.pointer, encodePointer(mergedKey));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@unsafe
|
|
45
|
+
public delete(_key: K): bool {
|
|
46
|
+
throw new Error('Method not implemented.');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@unsafe
|
|
50
|
+
public clear(): void {
|
|
51
|
+
throw new Error('Clear method not implemented.');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type MemorySlotData<T> = T;
|
|
1
|
+
export type MemorySlotData<T> = T;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { u256 } from 'as-bignum/assembly';
|
|
2
|
-
|
|
3
|
-
export type MemorySlotPointer = u256;
|
|
1
|
+
import { u256 } from 'as-bignum/assembly';
|
|
2
|
+
|
|
3
|
+
export type MemorySlotPointer = u256;
|
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import { MemorySlotData } from './MemorySlot';
|
|
2
|
-
import { u256 } from 'as-bignum/assembly';
|
|
3
|
-
import { KeyMerger } from './KeyMerger';
|
|
4
|
-
|
|
5
|
-
@final
|
|
6
|
-
export class MultiAddressMemoryMap<
|
|
7
|
-
K extends string,
|
|
8
|
-
K2 extends string,
|
|
9
|
-
V extends MemorySlotData<u256>,
|
|
10
|
-
> extends Map<K, KeyMerger<K, K2, V>> {
|
|
11
|
-
public pointer: u16;
|
|
12
|
-
|
|
13
|
-
constructor(
|
|
14
|
-
pointer: u16,
|
|
15
|
-
private readonly defaultValue: V,
|
|
16
|
-
) {
|
|
17
|
-
super();
|
|
18
|
-
|
|
19
|
-
this.pointer = pointer;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public get(key: K): KeyMerger<K, K2, V> {
|
|
23
|
-
this.createKeyMerger(key);
|
|
24
|
-
|
|
25
|
-
return super.get(key);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public setUpperKey(key: K, key2: K2, value: V): this {
|
|
29
|
-
this.createKeyMerger(key);
|
|
30
|
-
|
|
31
|
-
const subMap = super.get(key);
|
|
32
|
-
if (subMap) {
|
|
33
|
-
subMap.set(key2, value);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public set(key: K, value: KeyMerger<K, K2, V>): this {
|
|
40
|
-
this.createKeyMerger(key);
|
|
41
|
-
|
|
42
|
-
return <this>super.set(key, value);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public has(key: K): bool {
|
|
46
|
-
return super.has(key);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public delete(key: K): bool {
|
|
50
|
-
return super.delete(key);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public clear(): void {
|
|
54
|
-
super.clear();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private createKeyMerger(key: K): void {
|
|
58
|
-
if (!super.has(key)) {
|
|
59
|
-
super.set(key, new KeyMerger<K, K2, V>(key, this.pointer, this.defaultValue));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
1
|
+
import { MemorySlotData } from './MemorySlot';
|
|
2
|
+
import { u256 } from 'as-bignum/assembly';
|
|
3
|
+
import { KeyMerger } from './KeyMerger';
|
|
4
|
+
|
|
5
|
+
@final
|
|
6
|
+
export class MultiAddressMemoryMap<
|
|
7
|
+
K extends string,
|
|
8
|
+
K2 extends string,
|
|
9
|
+
V extends MemorySlotData<u256>,
|
|
10
|
+
> extends Map<K, KeyMerger<K, K2, V>> {
|
|
11
|
+
public pointer: u16;
|
|
12
|
+
|
|
13
|
+
constructor(
|
|
14
|
+
pointer: u16,
|
|
15
|
+
private readonly defaultValue: V,
|
|
16
|
+
) {
|
|
17
|
+
super();
|
|
18
|
+
|
|
19
|
+
this.pointer = pointer;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public get(key: K): KeyMerger<K, K2, V> {
|
|
23
|
+
this.createKeyMerger(key);
|
|
24
|
+
|
|
25
|
+
return super.get(key);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public setUpperKey(key: K, key2: K2, value: V): this {
|
|
29
|
+
this.createKeyMerger(key);
|
|
30
|
+
|
|
31
|
+
const subMap = super.get(key);
|
|
32
|
+
if (subMap) {
|
|
33
|
+
subMap.set(key2, value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public set(key: K, value: KeyMerger<K, K2, V>): this {
|
|
40
|
+
this.createKeyMerger(key);
|
|
41
|
+
|
|
42
|
+
return <this>super.set(key, value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public has(key: K): bool {
|
|
46
|
+
return super.has(key);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public delete(key: K): bool {
|
|
50
|
+
return super.delete(key);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public clear(): void {
|
|
54
|
+
super.clear();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private createKeyMerger(key: K): void {
|
|
58
|
+
if (!super.has(key)) {
|
|
59
|
+
super.set(key, new KeyMerger<K, K2, V>(key, this.pointer, this.defaultValue));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Address } from '../types/Address';
|
|
2
|
+
import { u256 } from 'as-bignum/assembly';
|
|
3
|
+
import { BytesWriter } from '../buffer/BytesWriter';
|
|
4
|
+
import { Blockchain } from '../env';
|
|
5
|
+
import { encodeSelector, Selector } from '../math/abi';
|
|
6
|
+
|
|
7
|
+
export class OP20Utils {
|
|
8
|
+
public static get BALANCE_OF_SELECTOR(): Selector {
|
|
9
|
+
return encodeSelector('balanceOf');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public static balanceOf(token: Address, owner: Address): u256 {
|
|
13
|
+
const calldata: BytesWriter = new BytesWriter();
|
|
14
|
+
calldata.writeSelector(OP20Utils.BALANCE_OF_SELECTOR);
|
|
15
|
+
calldata.writeAddress(owner);
|
|
16
|
+
|
|
17
|
+
const response = Blockchain.call(token, calldata);
|
|
18
|
+
|
|
19
|
+
return response.readU256();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import { u256 } from 'as-bignum/assembly/integer/u256';
|
|
2
|
-
import { encodeSelector, Selector } from '../math/abi';
|
|
3
|
-
import { Address } from '../types/Address';
|
|
4
|
-
import { BytesWriter } from '../buffer/BytesWriter';
|
|
5
|
-
import { Blockchain } from '../env';
|
|
6
|
-
import { Revert } from '../types/Revert';
|
|
7
|
-
|
|
8
|
-
export class TransferHelper {
|
|
9
|
-
public static get APPROVE_SELECTOR(): Selector {
|
|
10
|
-
return encodeSelector('approve');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public static get TRANSFER_SELECTOR(): Selector {
|
|
14
|
-
return encodeSelector('transfer');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public static get TRANSFER_FROM_SELECTOR(): Selector {
|
|
18
|
-
return encodeSelector('transferFrom');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public static safeApprove(token: Address, spender: Address, amount: u256): void {
|
|
22
|
-
const calldata = new BytesWriter();
|
|
23
|
-
calldata.writeSelector(this.APPROVE_SELECTOR);
|
|
24
|
-
calldata.writeAddress(spender);
|
|
25
|
-
calldata.writeU256(amount);
|
|
26
|
-
|
|
27
|
-
const response = Blockchain.call(token, calldata);
|
|
28
|
-
const isOk = response.readBoolean();
|
|
29
|
-
|
|
30
|
-
if (!isOk) {
|
|
31
|
-
throw new Revert(`TransferHelper: APPROVE_FAILED`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public static safeTransfer(token: Address, to: Address, amount: u256): void {
|
|
36
|
-
const calldata = new BytesWriter();
|
|
37
|
-
calldata.writeSelector(this.TRANSFER_SELECTOR);
|
|
38
|
-
calldata.writeAddress(to);
|
|
39
|
-
calldata.writeU256(amount);
|
|
40
|
-
|
|
41
|
-
const response = Blockchain.call(token, calldata);
|
|
42
|
-
const isOk = response.readBoolean();
|
|
43
|
-
|
|
44
|
-
if (!isOk) {
|
|
45
|
-
throw new Revert(`TransferHelper: TRANSFER_FAILED`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public static safeTransferFrom(token: Address, from: Address, to: Address, amount: u256): void {
|
|
50
|
-
const calldata = new BytesWriter();
|
|
51
|
-
calldata.writeSelector(this.TRANSFER_FROM_SELECTOR);
|
|
52
|
-
|
|
53
|
-
calldata.writeAddress(from);
|
|
54
|
-
calldata.writeAddress(to);
|
|
55
|
-
calldata.writeU256(amount);
|
|
56
|
-
|
|
57
|
-
const response = Blockchain.call(token, calldata);
|
|
58
|
-
const isOk = response.readBoolean();
|
|
59
|
-
|
|
60
|
-
if (!isOk) {
|
|
61
|
-
throw new Revert(`TransferHelper: TRANSFER_FROM_FAILED`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
1
|
+
import { u256 } from 'as-bignum/assembly/integer/u256';
|
|
2
|
+
import { encodeSelector, Selector } from '../math/abi';
|
|
3
|
+
import { Address } from '../types/Address';
|
|
4
|
+
import { BytesWriter } from '../buffer/BytesWriter';
|
|
5
|
+
import { Blockchain } from '../env';
|
|
6
|
+
import { Revert } from '../types/Revert';
|
|
7
|
+
|
|
8
|
+
export class TransferHelper {
|
|
9
|
+
public static get APPROVE_SELECTOR(): Selector {
|
|
10
|
+
return encodeSelector('approve');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public static get TRANSFER_SELECTOR(): Selector {
|
|
14
|
+
return encodeSelector('transfer');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public static get TRANSFER_FROM_SELECTOR(): Selector {
|
|
18
|
+
return encodeSelector('transferFrom');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public static safeApprove(token: Address, spender: Address, amount: u256): void {
|
|
22
|
+
const calldata = new BytesWriter();
|
|
23
|
+
calldata.writeSelector(this.APPROVE_SELECTOR);
|
|
24
|
+
calldata.writeAddress(spender);
|
|
25
|
+
calldata.writeU256(amount);
|
|
26
|
+
|
|
27
|
+
const response = Blockchain.call(token, calldata);
|
|
28
|
+
const isOk = response.readBoolean();
|
|
29
|
+
|
|
30
|
+
if (!isOk) {
|
|
31
|
+
throw new Revert(`TransferHelper: APPROVE_FAILED`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public static safeTransfer(token: Address, to: Address, amount: u256): void {
|
|
36
|
+
const calldata = new BytesWriter();
|
|
37
|
+
calldata.writeSelector(this.TRANSFER_SELECTOR);
|
|
38
|
+
calldata.writeAddress(to);
|
|
39
|
+
calldata.writeU256(amount);
|
|
40
|
+
|
|
41
|
+
const response = Blockchain.call(token, calldata);
|
|
42
|
+
const isOk = response.readBoolean();
|
|
43
|
+
|
|
44
|
+
if (!isOk) {
|
|
45
|
+
throw new Revert(`TransferHelper: TRANSFER_FAILED`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public static safeTransferFrom(token: Address, from: Address, to: Address, amount: u256): void {
|
|
50
|
+
const calldata = new BytesWriter();
|
|
51
|
+
calldata.writeSelector(this.TRANSFER_FROM_SELECTOR);
|
|
52
|
+
|
|
53
|
+
calldata.writeAddress(from);
|
|
54
|
+
calldata.writeAddress(to);
|
|
55
|
+
calldata.writeU256(amount);
|
|
56
|
+
|
|
57
|
+
const response = Blockchain.call(token, calldata);
|
|
58
|
+
const isOk = response.readBoolean();
|
|
59
|
+
|
|
60
|
+
if (!isOk) {
|
|
61
|
+
throw new Revert(`TransferHelper: TRANSFER_FROM_FAILED`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -3,6 +3,7 @@ import { Blockchain } from '../env';
|
|
|
3
3
|
import { MemorySlotPointer } from '../memory/MemorySlotPointer';
|
|
4
4
|
import { BytesWriter } from '../buffer/BytesWriter';
|
|
5
5
|
import { BytesReader } from '../buffer/BytesReader';
|
|
6
|
+
import { Revert } from '../types/Revert';
|
|
6
7
|
|
|
7
8
|
export abstract class Serializable {
|
|
8
9
|
protected pointer: u16;
|
|
@@ -15,7 +16,6 @@ export abstract class Serializable {
|
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
public abstract get chunkCount(): i32;
|
|
18
|
-
public abstract get length(): i32;
|
|
19
19
|
public abstract writeToBuffer(): BytesWriter;
|
|
20
20
|
public abstract readFromBuffer(reader: BytesReader): void;
|
|
21
21
|
|
|
@@ -60,7 +60,11 @@ export abstract class Serializable {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
protected chunksToBytes(chunks: u256[]): BytesReader {
|
|
63
|
-
|
|
63
|
+
if(this.chunkCount >= 67108863) {
|
|
64
|
+
throw new Revert('Too many chunks received');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const buffer: Uint8Array = new Uint8Array(this.chunkCount * 32);
|
|
64
68
|
let offset: i32 = 0;
|
|
65
69
|
|
|
66
70
|
for (let indexChunk: i32 = 0; indexChunk < chunks.length; indexChunk++) {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { u256 } from 'as-bignum/assembly';
|
|
2
|
+
import { Blockchain } from '../env';
|
|
3
|
+
|
|
4
|
+
@final
|
|
5
|
+
export class StoredBoolean {
|
|
6
|
+
constructor(
|
|
7
|
+
public pointer: u16,
|
|
8
|
+
private defaultValue: bool,
|
|
9
|
+
) {}
|
|
10
|
+
|
|
11
|
+
private _value: u256 = u256.Zero;
|
|
12
|
+
|
|
13
|
+
@inline
|
|
14
|
+
public get value(): bool {
|
|
15
|
+
this.ensureValue();
|
|
16
|
+
|
|
17
|
+
return this._value.toBool();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@inline
|
|
21
|
+
public set value(value: bool) {
|
|
22
|
+
this._value = value ? u256.One : u256.Zero;
|
|
23
|
+
|
|
24
|
+
Blockchain.setStorageAt(this.pointer, u256.Zero, this._value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@inline
|
|
28
|
+
public set(value: u256): this {
|
|
29
|
+
this._value = value;
|
|
30
|
+
|
|
31
|
+
Blockchain.setStorageAt(this.pointer, u256.Zero, this._value);
|
|
32
|
+
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@inline
|
|
37
|
+
public toUint8Array(): Uint8Array {
|
|
38
|
+
return this._value.toUint8Array(true);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private ensureValue(): void {
|
|
42
|
+
this._value = Blockchain.getStorageAt(
|
|
43
|
+
this.pointer,
|
|
44
|
+
u256.Zero,
|
|
45
|
+
this.defaultValue ? u256.One : u256.Zero,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|