@btc-vision/btc-runtime 1.0.4 → 1.0.6
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
CHANGED
|
@@ -11,6 +11,7 @@ import { Potential } from '../lang/Definitions';
|
|
|
11
11
|
import { Map } from '../generic/Map';
|
|
12
12
|
import { OP_NET } from '../contracts/OP_NET';
|
|
13
13
|
import { BlockchainStorage, PointerStorage } from '../types';
|
|
14
|
+
import { deploy, deployFromAddress } from './global';
|
|
14
15
|
|
|
15
16
|
export * from '../env/global';
|
|
16
17
|
|
|
@@ -172,6 +173,28 @@ export class BlockchainEnvironment {
|
|
|
172
173
|
return buffer.getBuffer();
|
|
173
174
|
}
|
|
174
175
|
|
|
176
|
+
public deployContract(hash: u256, bytecode: Uint8Array): BytesReader {
|
|
177
|
+
const writer = new BytesWriter();
|
|
178
|
+
writer.writeU256(hash);
|
|
179
|
+
writer.writeBytes(bytecode);
|
|
180
|
+
|
|
181
|
+
const cb: Potential<Uint8Array> = deploy(writer.getBuffer());
|
|
182
|
+
if (!cb) throw this.error('Failed to deploy contract');
|
|
183
|
+
|
|
184
|
+
return new BytesReader(cb as Uint8Array);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
public deployContractFromExisting(hash: u256, existingAddress: Address): BytesReader {
|
|
188
|
+
const writer = new BytesWriter();
|
|
189
|
+
writer.writeU256(hash);
|
|
190
|
+
writer.writeAddress(existingAddress);
|
|
191
|
+
|
|
192
|
+
const cb: Potential<Uint8Array> = deployFromAddress(writer.getBuffer());
|
|
193
|
+
if (!cb) throw this.error('Failed to deploy contract');
|
|
194
|
+
|
|
195
|
+
return new BytesReader(cb as Uint8Array);
|
|
196
|
+
}
|
|
197
|
+
|
|
175
198
|
public getStorageAt(
|
|
176
199
|
address: Address,
|
|
177
200
|
pointer: u16,
|
package/runtime/env/global.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import { u256 } from
|
|
2
|
-
import { Address } from "../types/Address";
|
|
1
|
+
import { u256 } from 'as-bignum/assembly/integer/u256';
|
|
3
2
|
|
|
4
3
|
// @ts-ignore
|
|
5
4
|
@external('env', 'load')
|
|
6
|
-
export declare function load(
|
|
5
|
+
export declare function load(data: Uint8Array): u256;
|
|
7
6
|
|
|
8
7
|
// @ts-ignore
|
|
9
8
|
@external('env', 'store')
|
|
10
|
-
export declare function store(
|
|
9
|
+
export declare function store(data: Uint8Array): void;
|
|
11
10
|
|
|
12
11
|
// @ts-ignore
|
|
13
12
|
@external('env', 'deploy')
|
|
14
|
-
export declare function deploy(
|
|
13
|
+
export declare function deploy(data: Uint8Array): Uint8Array;
|
|
14
|
+
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
@external('env', 'deployFromAddress')
|
|
17
|
+
export declare function deployFromAddress(data: Uint8Array): Uint8Array;
|
|
15
18
|
|
|
16
19
|
// @ts-ignore
|
|
17
20
|
@external('env', 'call')
|
|
18
|
-
export declare function call(
|
|
21
|
+
export declare function call(calldata: Uint8Array): Uint8Array;
|
|
@@ -29,6 +29,24 @@ export class StoredU256 {
|
|
|
29
29
|
return this._value;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
@inline
|
|
33
|
+
public set value(value: u256) {
|
|
34
|
+
this._value = value;
|
|
35
|
+
|
|
36
|
+
Blockchain.setStorageAt(
|
|
37
|
+
this.address,
|
|
38
|
+
this.pointer,
|
|
39
|
+
this.subPointer,
|
|
40
|
+
this._value,
|
|
41
|
+
this.defaultValue,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@inline
|
|
46
|
+
public get toBytes(): Uint8Array {
|
|
47
|
+
return this._value.toUint8Array(false);
|
|
48
|
+
}
|
|
49
|
+
|
|
32
50
|
@inline
|
|
33
51
|
@operator('+')
|
|
34
52
|
public add(value: u256): this {
|