@btc-vision/btc-runtime 1.5.2 → 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
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
|
@@ -329,12 +329,12 @@ export class BytesReader {
|
|
|
329
329
|
}
|
|
330
330
|
|
|
331
331
|
public readTransactionInputs(): TransactionInput[] {
|
|
332
|
-
const length = this.
|
|
332
|
+
const length = this.readU16();
|
|
333
333
|
const result = new Array<TransactionInput>(length);
|
|
334
334
|
|
|
335
335
|
for (let i: u16 = 0; i < length; i++) {
|
|
336
336
|
const txId = this.readBytes(32);
|
|
337
|
-
const outputIndex = this.
|
|
337
|
+
const outputIndex = this.readU16();
|
|
338
338
|
const scriptSig = this.readBytesWithLength();
|
|
339
339
|
result[i] = new TransactionInput(txId, outputIndex, scriptSig);
|
|
340
340
|
}
|
|
@@ -343,11 +343,11 @@ export class BytesReader {
|
|
|
343
343
|
}
|
|
344
344
|
|
|
345
345
|
public readTransactionOutputs(): TransactionOutput[] {
|
|
346
|
-
const length = this.
|
|
346
|
+
const length = this.readU16();
|
|
347
347
|
const result = new Array<TransactionOutput>(length);
|
|
348
348
|
|
|
349
349
|
for (let i: u16 = 0; i < length; i++) {
|
|
350
|
-
const index = this.
|
|
350
|
+
const index = this.readU16();
|
|
351
351
|
const scriptPubKey = this.readStringWithLength();
|
|
352
352
|
const value = this.readU64();
|
|
353
353
|
result[i] = new TransactionOutput(index, scriptPubKey, value);
|
|
@@ -9,16 +9,16 @@ import { Address } from '../types/Address';
|
|
|
9
9
|
import { Revert } from '../types/Revert';
|
|
10
10
|
import { SafeMath } from '../types/SafeMath';
|
|
11
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';
|
|
12
16
|
import { ApproveStr, TransferFromStr, TransferStr } from '../shared-libraries/TransferHelper';
|
|
13
17
|
import { Calldata } from '../types';
|
|
14
18
|
import { ADDRESS_BYTE_LENGTH, BOOLEAN_BYTE_LENGTH, U256_BYTE_LENGTH } from '../utils';
|
|
15
19
|
import { IOP_20 } from './interfaces/IOP_20';
|
|
16
20
|
import { OP20InitParameters } from './interfaces/OP20InitParameters';
|
|
17
21
|
import { OP_NET } from './OP_NET';
|
|
18
|
-
import { sha256 } from '../env/global';
|
|
19
|
-
import { EMPTY_POINTER } from '../math/bytes';
|
|
20
|
-
import { MapOfMap } from '../memory/MapOfMap';
|
|
21
|
-
import { AddressMemoryMap } from '../memory/AddressMemoryMap';
|
|
22
22
|
|
|
23
23
|
const nonceMapPointer: u16 = Blockchain.nextPointer;
|
|
24
24
|
const maxSupplyPointer: u16 = Blockchain.nextPointer;
|
|
@@ -84,12 +84,15 @@ export abstract class DeployableOP_20 extends OP_NET implements IOP_20 {
|
|
|
84
84
|
return this._symbol.value;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
public instantiate(
|
|
87
|
+
public instantiate(
|
|
88
|
+
params: OP20InitParameters,
|
|
89
|
+
skipDeployerVerification: boolean = false,
|
|
90
|
+
): void {
|
|
88
91
|
if (!this._maxSupply.value.isZero()) {
|
|
89
92
|
throw new Revert('Already initialized');
|
|
90
93
|
}
|
|
91
94
|
|
|
92
|
-
if (!
|
|
95
|
+
if (!skipDeployerVerification) this.onlyDeployer(Blockchain.tx.sender);
|
|
93
96
|
|
|
94
97
|
if (params.decimals > 32) {
|
|
95
98
|
throw new Revert('Decimals can not be more than 32');
|
|
@@ -446,8 +449,8 @@ export abstract class DeployableOP_20 extends OP_NET implements IOP_20 {
|
|
|
446
449
|
this.emitEvent(approveEvent);
|
|
447
450
|
}
|
|
448
451
|
|
|
449
|
-
protected createMintEvent(
|
|
450
|
-
const mintEvent = new MintEvent(
|
|
452
|
+
protected createMintEvent(recipient: Address, value: u256): void {
|
|
453
|
+
const mintEvent = new MintEvent(recipient, value);
|
|
451
454
|
this.emitEvent(mintEvent);
|
|
452
455
|
}
|
|
453
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
|
}
|
|
@@ -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
|
) {
|