@btc-vision/btc-runtime 1.9.7 → 1.9.8

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.8",
4
4
  "description": "Bitcoin Smart Contract Runtime",
5
5
  "main": "btc/index.ts",
6
6
  "scripts": {
@@ -24,13 +24,7 @@ import { IOP721 } from './interfaces/IOP721';
24
24
  import { OP721InitParameters } from './interfaces/OP721InitParameters';
25
25
  import { ReentrancyGuard } from './ReentrancyGuard';
26
26
  import { StoredMapU256 } from '../storage/maps/StoredMapU256';
27
- import {
28
- ApprovedEvent,
29
- ApprovedForAllEvent,
30
- MAX_URI_LENGTH,
31
- TransferredEvent,
32
- URIEvent,
33
- } from '../events/predefined';
27
+ import { ApprovedEvent, ApprovedForAllEvent, MAX_URI_LENGTH, TransferredEvent, URIEvent, } from '../events/predefined';
34
28
  import {
35
29
  ON_OP721_RECEIVED_SELECTOR,
36
30
  OP712_DOMAIN_TYPE_HASH,
@@ -39,10 +33,7 @@ import {
39
33
  OP721_TRANSFER_TYPE_HASH,
40
34
  } from '../constants/Exports';
41
35
 
42
- // Storage pointers
43
- const namePointer: u16 = Blockchain.nextPointer;
44
- const symbolPointer: u16 = Blockchain.nextPointer;
45
- const baseURIPointer: u16 = Blockchain.nextPointer;
36
+ const stringPointer: u16 = Blockchain.nextPointer;
46
37
  const totalSupplyPointer: u16 = Blockchain.nextPointer;
47
38
  const maxSupplyPointer: u16 = Blockchain.nextPointer;
48
39
  const ownerOfMapPointer: u16 = Blockchain.nextPointer;
@@ -62,6 +53,11 @@ export abstract class OP721 extends ReentrancyGuard implements IOP721 {
62
53
  protected readonly _name: StoredString;
63
54
  protected readonly _symbol: StoredString;
64
55
  protected readonly _baseURI: StoredString;
56
+ protected readonly _collectionBanner: StoredString;
57
+ protected readonly _collectionIcon: StoredString;
58
+ protected readonly _collectionDescription: StoredString;
59
+ protected readonly _collectionWebsite: StoredString;
60
+
65
61
  protected readonly _totalSupply: StoredU256;
66
62
  protected readonly _maxSupply: StoredU256;
67
63
  protected readonly _nextTokenId: StoredU256;
@@ -90,9 +86,14 @@ export abstract class OP721 extends ReentrancyGuard implements IOP721 {
90
86
  public constructor() {
91
87
  super();
92
88
 
93
- this._name = new StoredString(namePointer, 0);
94
- this._symbol = new StoredString(symbolPointer, 0);
95
- this._baseURI = new StoredString(baseURIPointer, 0);
89
+ this._name = new StoredString(stringPointer, 0);
90
+ this._symbol = new StoredString(stringPointer, 2);
91
+ this._baseURI = new StoredString(stringPointer, 3);
92
+ this._collectionBanner = new StoredString(stringPointer, 4);
93
+ this._collectionIcon = new StoredString(stringPointer, 5);
94
+ this._collectionDescription = new StoredString(stringPointer, 6);
95
+ this._collectionWebsite = new StoredString(stringPointer, 7);
96
+
96
97
  this._totalSupply = new StoredU256(totalSupplyPointer, EMPTY_POINTER);
97
98
  this._maxSupply = new StoredU256(maxSupplyPointer, EMPTY_POINTER);
98
99
  this._nextTokenId = new StoredU256(nextTokenIdPointer, EMPTY_POINTER);
@@ -132,6 +133,22 @@ export abstract class OP721 extends ReentrancyGuard implements IOP721 {
132
133
  return this._maxSupply.value;
133
134
  }
134
135
 
136
+ public get collectionBanner(): string {
137
+ return this._collectionBanner.value;
138
+ }
139
+
140
+ public get collectionIcon(): string {
141
+ return this._collectionIcon.value;
142
+ }
143
+
144
+ public get collectionDescription(): string {
145
+ return this._collectionDescription.value;
146
+ }
147
+
148
+ public get collectionWebsite(): string {
149
+ return this._collectionWebsite.value;
150
+ }
151
+
135
152
  public instantiate(
136
153
  params: OP721InitParameters,
137
154
  skipDeployerVerification: boolean = false,
@@ -150,6 +167,11 @@ export abstract class OP721 extends ReentrancyGuard implements IOP721 {
150
167
  this._nextTokenId.value = u256.One;
151
168
  this._initialized.value = u256.One;
152
169
  this._tokenURICounter.value = u256.Zero;
170
+
171
+ this._collectionBanner.value = params.collectionBanner;
172
+ this._collectionIcon.value = params.collectionIcon;
173
+ this._collectionDescription.value = params.collectionDescription;
174
+ this._collectionWebsite.value = params.collectionWebsite;
153
175
  }
154
176
 
155
177
  @method('name')
@@ -178,6 +200,28 @@ export abstract class OP721 extends ReentrancyGuard implements IOP721 {
178
200
  return w;
179
201
  }
180
202
 
203
+ @method('collectionInfo')
204
+ @returns(
205
+ { name: 'icon', type: ABIDataTypes.STRING },
206
+ { name: 'banner', type: ABIDataTypes.STRING },
207
+ { name: 'description', type: ABIDataTypes.STRING },
208
+ { name: 'website', type: ABIDataTypes.STRING },
209
+ )
210
+ public collectionInfo(_: Calldata): BytesWriter {
211
+ const length =
212
+ String.UTF8.byteLength(this.collectionIcon) +
213
+ String.UTF8.byteLength(this.collectionDescription) +
214
+ String.UTF8.byteLength(this.collectionWebsite) +
215
+ String.UTF8.byteLength(this.collectionBanner);
216
+
217
+ const w = new BytesWriter(U32_BYTE_LENGTH * 4 + length);
218
+ w.writeStringWithLength(this.collectionIcon);
219
+ w.writeStringWithLength(this.collectionBanner);
220
+ w.writeStringWithLength(this.collectionDescription);
221
+ w.writeStringWithLength(this.collectionWebsite);
222
+ return w;
223
+ }
224
+
181
225
  @method({ name: 'tokenId', type: ABIDataTypes.UINT256 })
182
226
  @returns({ name: 'uri', type: ABIDataTypes.STRING })
183
227
  public tokenURI(calldata: Calldata): BytesWriter {
@@ -465,6 +509,60 @@ export abstract class OP721 extends ReentrancyGuard implements IOP721 {
465
509
  return new BytesWriter(0);
466
510
  }
467
511
 
512
+ @method()
513
+ @returns(
514
+ { name: 'name', type: ABIDataTypes.STRING },
515
+ { name: 'symbol', type: ABIDataTypes.STRING },
516
+ { name: 'icon', type: ABIDataTypes.STRING },
517
+ { name: 'banner', type: ABIDataTypes.STRING },
518
+ { name: 'description', type: ABIDataTypes.STRING },
519
+ { name: 'website', type: ABIDataTypes.STRING },
520
+ { name: 'totalSupply', type: ABIDataTypes.UINT256 },
521
+ { name: 'maximumSupply', type: ABIDataTypes.UINT256 },
522
+ { name: 'domainSeparator', type: ABIDataTypes.BYTES32 },
523
+ )
524
+ public metadata(_: Calldata): BytesWriter {
525
+ const name = this.name;
526
+ const symbol = this.symbol;
527
+ const icon = this.collectionIcon;
528
+ const banner = this.collectionBanner;
529
+ const description = this.collectionDescription;
530
+ const website = this.collectionWebsite;
531
+ const domainSeparator = this._buildDomainSeparator();
532
+
533
+ const nameLength = String.UTF8.byteLength(name);
534
+ const symbolLength = String.UTF8.byteLength(symbol);
535
+ const iconLength = String.UTF8.byteLength(icon);
536
+ const bannerLength = String.UTF8.byteLength(banner);
537
+ const descriptionLength = String.UTF8.byteLength(description);
538
+ const websiteLength = String.UTF8.byteLength(website);
539
+
540
+ const totalSize =
541
+ U32_BYTE_LENGTH * 6 +
542
+ nameLength +
543
+ symbolLength +
544
+ iconLength +
545
+ bannerLength +
546
+ descriptionLength +
547
+ websiteLength +
548
+ U256_BYTE_LENGTH * 2 +
549
+ U32_BYTE_LENGTH +
550
+ domainSeparator.length;
551
+
552
+ const w = new BytesWriter(totalSize);
553
+ w.writeStringWithLength(name);
554
+ w.writeStringWithLength(symbol);
555
+ w.writeStringWithLength(icon);
556
+ w.writeStringWithLength(banner);
557
+ w.writeStringWithLength(description);
558
+ w.writeStringWithLength(website);
559
+ w.writeU256(this.totalSupply);
560
+ w.writeU256(this.maxSupply);
561
+ w.writeBytesWithLength(domainSeparator);
562
+
563
+ return w;
564
+ }
565
+
468
566
  protected _mint(to: Address, tokenId: u256): void {
469
567
  if (to === Address.zero() || to === Address.dead()) {
470
568
  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
  }