@btc-vision/btc-runtime 1.9.7 → 1.9.9

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.9.7",
3
+ "version": "1.9.9",
4
4
  "description": "Bitcoin Smart Contract Runtime",
5
5
  "main": "btc/index.ts",
6
6
  "scripts": {
@@ -284,6 +284,15 @@ export class BytesReader {
284
284
  return result;
285
285
  }
286
286
 
287
+ public readU8Array(be: boolean = true): u8[] {
288
+ const length = this.readU16(be);
289
+ const result = new Array<u8>(length);
290
+ for (let i: u16 = 0; i < length; i++) {
291
+ result[i] = this.readU8();
292
+ }
293
+ return result;
294
+ }
295
+
287
296
  public readU128Array(be: boolean = true): u128[] {
288
297
  const length = this.readU16(be);
289
298
  const result = new Array<u128>(length);
@@ -197,6 +197,16 @@ export class BytesWriter {
197
197
 
198
198
  // ------------------ Array Writers ------------------ //
199
199
 
200
+ public writeU8Array(value: u8[], be: boolean = true): void {
201
+ if (value.length > 65535) throw new Revert('Array size is too large');
202
+ this.allocSafe(U16_BYTE_LENGTH + value.length);
203
+ this.writeU16(u16(value.length), be);
204
+
205
+ for (let i = 0; i < value.length; i++) {
206
+ this.writeU8(value[i]);
207
+ }
208
+ }
209
+
200
210
  public writeU16Array(value: u16[], be: boolean = true): void {
201
211
  if (value.length > 65535) throw new Revert('Array size is too large');
202
212
  this.allocSafe(U16_BYTE_LENGTH + value.length * U16_BYTE_LENGTH);
@@ -39,10 +39,7 @@ import {
39
39
  OP721_TRANSFER_TYPE_HASH,
40
40
  } from '../constants/Exports';
41
41
 
42
- // Storage pointers
43
- const namePointer: u16 = Blockchain.nextPointer;
44
- const symbolPointer: u16 = Blockchain.nextPointer;
45
- const baseURIPointer: u16 = Blockchain.nextPointer;
42
+ const stringPointer: u16 = Blockchain.nextPointer;
46
43
  const totalSupplyPointer: u16 = Blockchain.nextPointer;
47
44
  const maxSupplyPointer: u16 = Blockchain.nextPointer;
48
45
  const ownerOfMapPointer: u16 = Blockchain.nextPointer;
@@ -62,6 +59,11 @@ export abstract class OP721 extends ReentrancyGuard implements IOP721 {
62
59
  protected readonly _name: StoredString;
63
60
  protected readonly _symbol: StoredString;
64
61
  protected readonly _baseURI: StoredString;
62
+ protected readonly _collectionBanner: StoredString;
63
+ protected readonly _collectionIcon: StoredString;
64
+ protected readonly _collectionDescription: StoredString;
65
+ protected readonly _collectionWebsite: StoredString;
66
+
65
67
  protected readonly _totalSupply: StoredU256;
66
68
  protected readonly _maxSupply: StoredU256;
67
69
  protected readonly _nextTokenId: StoredU256;
@@ -90,9 +92,14 @@ export abstract class OP721 extends ReentrancyGuard implements IOP721 {
90
92
  public constructor() {
91
93
  super();
92
94
 
93
- this._name = new StoredString(namePointer, 0);
94
- this._symbol = new StoredString(symbolPointer, 0);
95
- this._baseURI = new StoredString(baseURIPointer, 0);
95
+ this._name = new StoredString(stringPointer, 0);
96
+ this._symbol = new StoredString(stringPointer, 2);
97
+ this._baseURI = new StoredString(stringPointer, 3);
98
+ this._collectionBanner = new StoredString(stringPointer, 4);
99
+ this._collectionIcon = new StoredString(stringPointer, 5);
100
+ this._collectionDescription = new StoredString(stringPointer, 6);
101
+ this._collectionWebsite = new StoredString(stringPointer, 7);
102
+
96
103
  this._totalSupply = new StoredU256(totalSupplyPointer, EMPTY_POINTER);
97
104
  this._maxSupply = new StoredU256(maxSupplyPointer, EMPTY_POINTER);
98
105
  this._nextTokenId = new StoredU256(nextTokenIdPointer, EMPTY_POINTER);
@@ -132,6 +139,22 @@ export abstract class OP721 extends ReentrancyGuard implements IOP721 {
132
139
  return this._maxSupply.value;
133
140
  }
134
141
 
142
+ public get collectionBanner(): string {
143
+ return this._collectionBanner.value;
144
+ }
145
+
146
+ public get collectionIcon(): string {
147
+ return this._collectionIcon.value;
148
+ }
149
+
150
+ public get collectionDescription(): string {
151
+ return this._collectionDescription.value;
152
+ }
153
+
154
+ public get collectionWebsite(): string {
155
+ return this._collectionWebsite.value;
156
+ }
157
+
135
158
  public instantiate(
136
159
  params: OP721InitParameters,
137
160
  skipDeployerVerification: boolean = false,
@@ -150,6 +173,11 @@ export abstract class OP721 extends ReentrancyGuard implements IOP721 {
150
173
  this._nextTokenId.value = u256.One;
151
174
  this._initialized.value = u256.One;
152
175
  this._tokenURICounter.value = u256.Zero;
176
+
177
+ this._collectionBanner.value = params.collectionBanner;
178
+ this._collectionIcon.value = params.collectionIcon;
179
+ this._collectionDescription.value = params.collectionDescription;
180
+ this._collectionWebsite.value = params.collectionWebsite;
153
181
  }
154
182
 
155
183
  @method('name')
@@ -178,6 +206,28 @@ export abstract class OP721 extends ReentrancyGuard implements IOP721 {
178
206
  return w;
179
207
  }
180
208
 
209
+ @method('collectionInfo')
210
+ @returns(
211
+ { name: 'icon', type: ABIDataTypes.STRING },
212
+ { name: 'banner', type: ABIDataTypes.STRING },
213
+ { name: 'description', type: ABIDataTypes.STRING },
214
+ { name: 'website', type: ABIDataTypes.STRING },
215
+ )
216
+ public collectionInfo(_: Calldata): BytesWriter {
217
+ const length =
218
+ String.UTF8.byteLength(this.collectionIcon) +
219
+ String.UTF8.byteLength(this.collectionDescription) +
220
+ String.UTF8.byteLength(this.collectionWebsite) +
221
+ String.UTF8.byteLength(this.collectionBanner);
222
+
223
+ const w = new BytesWriter(U32_BYTE_LENGTH * 4 + length);
224
+ w.writeStringWithLength(this.collectionIcon);
225
+ w.writeStringWithLength(this.collectionBanner);
226
+ w.writeStringWithLength(this.collectionDescription);
227
+ w.writeStringWithLength(this.collectionWebsite);
228
+ return w;
229
+ }
230
+
181
231
  @method({ name: 'tokenId', type: ABIDataTypes.UINT256 })
182
232
  @returns({ name: 'uri', type: ABIDataTypes.STRING })
183
233
  public tokenURI(calldata: Calldata): BytesWriter {
@@ -207,6 +257,28 @@ export abstract class OP721 extends ReentrancyGuard implements IOP721 {
207
257
  return w;
208
258
  }
209
259
 
260
+ @method('changeMetadata')
261
+ public changeMetadata(calldata: Calldata): BytesWriter {
262
+ this.onlyDeployer(Blockchain.tx.sender);
263
+
264
+ const icon: string = calldata.readStringWithLength();
265
+ const banner: string = calldata.readStringWithLength();
266
+ const description: string = calldata.readStringWithLength();
267
+ const website: string = calldata.readStringWithLength();
268
+
269
+ if (icon.length == 0) throw new Revert('Icon cannot be empty');
270
+ if (banner.length == 0) throw new Revert('Banner cannot be empty');
271
+ if (description.length == 0) throw new Revert('Description cannot be empty');
272
+ if (website.length == 0) throw new Revert('Website cannot be empty');
273
+
274
+ this._collectionIcon.value = icon;
275
+ this._collectionBanner.value = banner;
276
+ this._collectionDescription.value = description;
277
+ this._collectionWebsite.value = website;
278
+
279
+ return new BytesWriter(0);
280
+ }
281
+
210
282
  @method('totalSupply')
211
283
  @returns({ name: 'totalSupply', type: ABIDataTypes.UINT256 })
212
284
  public fn_totalSupply(_: Calldata): BytesWriter {
@@ -465,6 +537,60 @@ export abstract class OP721 extends ReentrancyGuard implements IOP721 {
465
537
  return new BytesWriter(0);
466
538
  }
467
539
 
540
+ @method()
541
+ @returns(
542
+ { name: 'name', type: ABIDataTypes.STRING },
543
+ { name: 'symbol', type: ABIDataTypes.STRING },
544
+ { name: 'icon', type: ABIDataTypes.STRING },
545
+ { name: 'banner', type: ABIDataTypes.STRING },
546
+ { name: 'description', type: ABIDataTypes.STRING },
547
+ { name: 'website', type: ABIDataTypes.STRING },
548
+ { name: 'totalSupply', type: ABIDataTypes.UINT256 },
549
+ { name: 'maximumSupply', type: ABIDataTypes.UINT256 },
550
+ { name: 'domainSeparator', type: ABIDataTypes.BYTES32 },
551
+ )
552
+ public metadata(_: Calldata): BytesWriter {
553
+ const name = this.name;
554
+ const symbol = this.symbol;
555
+ const icon = this.collectionIcon;
556
+ const banner = this.collectionBanner;
557
+ const description = this.collectionDescription;
558
+ const website = this.collectionWebsite;
559
+ const domainSeparator = this._buildDomainSeparator();
560
+
561
+ const nameLength = String.UTF8.byteLength(name);
562
+ const symbolLength = String.UTF8.byteLength(symbol);
563
+ const iconLength = String.UTF8.byteLength(icon);
564
+ const bannerLength = String.UTF8.byteLength(banner);
565
+ const descriptionLength = String.UTF8.byteLength(description);
566
+ const websiteLength = String.UTF8.byteLength(website);
567
+
568
+ const totalSize =
569
+ U32_BYTE_LENGTH * 6 +
570
+ nameLength +
571
+ symbolLength +
572
+ iconLength +
573
+ bannerLength +
574
+ descriptionLength +
575
+ websiteLength +
576
+ U256_BYTE_LENGTH * 2 +
577
+ U32_BYTE_LENGTH +
578
+ domainSeparator.length;
579
+
580
+ const w = new BytesWriter(totalSize);
581
+ w.writeStringWithLength(name);
582
+ w.writeStringWithLength(symbol);
583
+ w.writeStringWithLength(icon);
584
+ w.writeStringWithLength(banner);
585
+ w.writeStringWithLength(description);
586
+ w.writeStringWithLength(website);
587
+ w.writeU256(this.totalSupply);
588
+ w.writeU256(this.maxSupply);
589
+ w.writeBytesWithLength(domainSeparator);
590
+
591
+ return w;
592
+ }
593
+
468
594
  protected _mint(to: Address, tokenId: u256): void {
469
595
  if (to === Address.zero() || to === Address.dead()) {
470
596
  throw new Revert('Cannot mint to zero address');
@@ -6,10 +6,29 @@ export class OP721InitParameters {
6
6
  public baseURI: string;
7
7
  public maxSupply: u256;
8
8
 
9
- constructor(name: string, symbol: string, baseURI: string, maxSupply: u256) {
9
+ public collectionBanner: string;
10
+ public collectionIcon: string;
11
+ public collectionWebsite: string;
12
+ public collectionDescription: string;
13
+
14
+ constructor(
15
+ name: string,
16
+ symbol: string,
17
+ baseURI: string,
18
+ maxSupply: u256,
19
+ collectionBanner: string = '',
20
+ collectionIcon: string = '',
21
+ collectionWebsite: string = '',
22
+ collectionDescription: string = '',
23
+ ) {
10
24
  this.name = name;
11
25
  this.symbol = symbol;
12
26
  this.baseURI = baseURI;
13
27
  this.maxSupply = maxSupply;
28
+
29
+ this.collectionBanner = collectionBanner;
30
+ this.collectionIcon = collectionIcon;
31
+ this.collectionWebsite = collectionWebsite;
32
+ this.collectionDescription = collectionDescription;
14
33
  }
15
34
  }