Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | 109x 109x 109x 109x 109x 109x 109x 109x 1x 1x 95x 95x 208x 208x 109x 109x 109x 99x 99x 99x | // @todo: add data!
import { Change } from "../changelog";
import { validateCollection } from "../../tools/validate-remark";
import { getRemarkData } from "../../tools/utils";
import { OP_TYPES, VERSION } from "../../tools/constants";
export class Collection {
readonly block: number;
readonly name: string;
readonly max: number;
issuer: string;
readonly symbol: string;
readonly id: string;
readonly metadata: string;
private changes: Change[] = [];
loadedMetadata?: CollectionMetadata;
constructor(
block: number,
name: string,
max: number,
issuer: string,
symbol: string,
id: string,
metadata: string
) {
this.block = block;
this.name = name;
this.max = max;
this.issuer = issuer;
this.symbol = symbol;
this.id = id;
this.metadata = metadata;
}
public mint(): string {
if (this.block) {
throw new Error("An already existing collection cannot be minted!");
}
return `RMRK::${OP_TYPES.MINT}::${VERSION}::${encodeURIComponent(
JSON.stringify({
name: this.name,
max: this.max,
issuer: this.issuer,
symbol: this.symbol.toUpperCase(),
id: this.id,
metadata: this.metadata,
})
)}`;
}
public change_issuer(address: string): string {
if (this.block === 0) {
throw new Error(
"This collection is new, so there's no issuer to change." +
" If it has been deployed on chain, load the existing " +
"collection as a new instance first, then change issuer."
);
}
return `RMRK::CHANGEISSUER::${VERSION}::${this.id}::${address}`;
}
public addChange(c: Change): Collection {
this.changes.push(c);
return this;
}
public getChanges(): Change[] {
return this.changes;
}
static generateId(pubkey: string, symbol: string): string {
Iif (!pubkey.startsWith("0x")) {
throw new Error("This is not a valid pubkey, it does not start with 0x");
}
//console.log(pubkey);
return (
pubkey.substr(2, 10) +
pubkey.substring(pubkey.length - 8) +
"-" +
symbol.toUpperCase()
);
}
static fromRemark(remark: string, block = 0): Collection | string {
try {
validateCollection(remark);
const [prefix, op_type, version, dataString] = remark.split("::");
const obj = getRemarkData(dataString);
return new this(
block,
obj.name,
obj.max,
obj.issuer,
obj.symbol,
obj.id,
obj.metadata
);
} catch (e) {
console.error(e.message);
console.log(`${OP_TYPES.MINT} error: full input was ${remark}`);
return e.message;
}
}
/**
* TBD - hard dependency on Axios / IPFS to fetch remote
*/
private async load_metadata(): Promise<CollectionMetadata> {
if (this.loadedMetadata) return this.loadedMetadata;
return {} as CollectionMetadata;
}
}
export interface CollectionMetadata {
description?: string;
attributes: Attribute[];
external_url?: string;
image?: string;
image_data?: string;
}
export interface Attribute {
display_type: DisplayType;
trait_type: string;
value: number | string;
}
export enum DisplayType {
null,
"boost_number",
"number",
"boost_percentage",
}
|