@btc-vision/btc-runtime 1.3.11 → 1.3.12

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btc-vision/btc-runtime",
3
- "version": "1.3.11",
3
+ "version": "1.3.12",
4
4
  "description": "Bitcoin Smart Contract Runtime",
5
5
  "main": "btc/index.ts",
6
6
  "scripts": {
@@ -86,7 +86,7 @@ export abstract class DeployableOP_20 extends OP_NET implements IOP_20 {
86
86
  throw new Revert('Already initialized');
87
87
  }
88
88
 
89
- if (!skipOwnerVerification) this.onlyOwner(Blockchain.tx.sender);
89
+ if (!skipOwnerVerification) this.onlyDeployer(Blockchain.tx.sender);
90
90
 
91
91
  if (params.decimals > 32) {
92
92
  throw new Revert('Decimals can not be more than 32');
@@ -237,12 +237,12 @@ export abstract class DeployableOP_20 extends OP_NET implements IOP_20 {
237
237
  return this.balanceOfMap.get(owner);
238
238
  }
239
239
 
240
- protected _burn(value: u256, onlyOwner: boolean = true): boolean {
240
+ protected _burn(value: u256, onlyDeployer: boolean = true): boolean {
241
241
  if (u256.eq(value, u256.Zero)) {
242
242
  throw new Revert(`No tokens`);
243
243
  }
244
244
 
245
- if (onlyOwner) this.onlyOwner(Blockchain.tx.sender);
245
+ if (onlyDeployer) this.onlyDeployer(Blockchain.tx.sender);
246
246
 
247
247
  if (this._totalSupply.value < value) throw new Revert(`Insufficient total supply.`);
248
248
  if (!this.balanceOfMap.has(Blockchain.tx.sender)) throw new Revert('No balance');
@@ -260,8 +260,8 @@ export abstract class DeployableOP_20 extends OP_NET implements IOP_20 {
260
260
  return true;
261
261
  }
262
262
 
263
- protected _mint(to: Address, value: u256, onlyOwner: boolean = true): boolean {
264
- if (onlyOwner) this.onlyOwner(Blockchain.tx.sender);
263
+ protected _mint(to: Address, value: u256, onlyDeployer: boolean = true): boolean {
264
+ if (onlyDeployer) this.onlyDeployer(Blockchain.tx.sender);
265
265
 
266
266
  if (!this.balanceOfMap.has(to)) {
267
267
  this.balanceOfMap.set(to, value);
@@ -12,8 +12,8 @@ export class OP_NET implements IBTC {
12
12
  return Blockchain.contractAddress;
13
13
  }
14
14
 
15
- public get owner(): Address {
16
- return Blockchain.owner;
15
+ public get contractDeployer(): Address {
16
+ return Blockchain.contractDeployer;
17
17
  }
18
18
 
19
19
  public onDeployment(_calldata: Calldata): void {}
@@ -26,7 +26,7 @@ export class OP_NET implements IBTC {
26
26
  switch (method) {
27
27
  case encodeSelector('owner'):
28
28
  response = new BytesWriter(ADDRESS_BYTE_LENGTH);
29
- response.writeAddress(this.owner);
29
+ response.writeAddress(this.contractDeployer);
30
30
  break;
31
31
  default:
32
32
  throw new Revert('Method not found');
@@ -47,8 +47,8 @@ export class OP_NET implements IBTC {
47
47
  return this.address === address;
48
48
  }
49
49
 
50
- protected onlyOwner(caller: Address): void {
51
- if (this.owner !== caller) {
50
+ protected onlyDeployer(caller: Address): void {
51
+ if (this.contractDeployer !== caller) {
52
52
  throw new Revert('Only owner can call this method');
53
53
  }
54
54
  }
@@ -87,14 +87,14 @@ export class BlockchainEnvironment {
87
87
  return this._nextPointer;
88
88
  }
89
89
 
90
- public _owner: Potential<Address> = null;
90
+ public _contractDeployer: Potential<Address> = null;
91
91
 
92
- public get owner(): Address {
93
- if (!this._owner) {
94
- throw this.error('Owner is required');
92
+ public get contractDeployer(): Address {
93
+ if (!this._contractDeployer) {
94
+ throw this.error('Deployer is required');
95
95
  }
96
96
 
97
- return this._owner as Address;
97
+ return this._contractDeployer as Address;
98
98
  }
99
99
 
100
100
  public _contractAddress: Potential<Address> = null;
@@ -118,7 +118,7 @@ export class BlockchainEnvironment {
118
118
 
119
119
  const currentBlock = reader.readU256();
120
120
 
121
- this._owner = reader.readAddress();
121
+ this._contractDeployer = reader.readAddress();
122
122
  this._contractAddress = reader.readAddress();
123
123
 
124
124
  const medianTimestamp = reader.readU64();
@@ -1,6 +1,6 @@
1
1
  import { Address } from '../types/Address';
2
2
 
3
3
  export interface IBTC {
4
- readonly owner: Address;
4
+ readonly contractDeployer: Address;
5
5
  readonly address: Address;
6
6
  }
@@ -6,6 +6,7 @@ import { BytesReader } from '../buffer/BytesReader';
6
6
  import { Revert } from '../types/Revert';
7
7
  import { encodePointer } from '../math/abi';
8
8
 
9
+ // Similar to a struct in Solidity. (Use in worst case scenario, consume a lot of gas)
9
10
  export abstract class Serializable {
10
11
  protected pointer: u16;
11
12
  protected subPointer: MemorySlotPointer;
@@ -58,7 +59,7 @@ export abstract class Serializable {
58
59
  );
59
60
  }
60
61
 
61
- for (let index: i32 = 0; index < chunks.length; index++) {
62
+ for (let index: u8 = 0; index < u8(chunks.length); index++) {
62
63
  Blockchain.setStorageAt(this.getPointer(this.subPointer, index), chunks[index]);
63
64
  }
64
65
  }
@@ -79,7 +80,8 @@ export abstract class Serializable {
79
80
  }
80
81
 
81
82
  protected chunksToBytes(chunks: u256[]): BytesReader {
82
- if (this.chunkCount >= 67108863) {
83
+ if (this.chunkCount >= u8(255)) {
84
+ //67108863
83
85
  throw new Revert('Too many chunks received');
84
86
  }
85
87