Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose types from tools/types #97

Open
wants to merge 38 commits into
base: chore/split-types
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
bae40f9
Update README.md
Yuripetusko Feb 9, 2022
43d752c
Update README.md
Yuripetusko Feb 9, 2022
6e7c5fb
Allow equip in slot with "*" whitelisting
Yuripetusko Feb 10, 2022
3642c61
v2.0.41
Yuripetusko Feb 10, 2022
21d0efc
Save extra balance transfers alongside BUY change
Yuripetusko Feb 14, 2022
5d90375
Merge pull request #91 from rmrk-team/feat/save-extra-balance-transfe…
Yuripetusko Feb 14, 2022
5d35fe2
update tests
Yuripetusko Feb 14, 2022
920537d
Merge branch 'feat/save-extra-balance-transfers-alongside-buy'
Yuripetusko Feb 14, 2022
f1f14ab
v2.0.43
Yuripetusko Feb 14, 2022
854c56d
only save extraTransfers on BUY change for field "forsale"
Yuripetusko Feb 17, 2022
21dc19e
v2.0.44
Yuripetusko Feb 17, 2022
1c75901
Make Base type optional field and change validation to any string
Yuripetusko Feb 20, 2022
d07ecc1
Merge branch 'master' of github.com:rmrk-team/rmrk-tools
Yuripetusko Feb 20, 2022
8cc1268
Update consolidator.ts
Yuripetusko Feb 20, 2022
b405c53
v2.0.46
Yuripetusko Feb 20, 2022
89a971a
save rootowner in old field of BUY change
Yuripetusko Feb 21, 2022
cbfb350
Update buy.test.ts.snap
Yuripetusko Feb 21, 2022
9ffa513
safe validateDecode
Yuripetusko Feb 24, 2022
4c4088a
v2.0.47
Yuripetusko Feb 24, 2022
1e9d979
v1.0.40-rc.2
Yuripetusko Feb 26, 2022
6518bc0
substra no longer guatranteed finalised block emission
Yuripetusko Feb 26, 2022
a829013
v2.0.49
Yuripetusko Feb 26, 2022
a1436dc
Update listener.ts
Yuripetusko Feb 26, 2022
54e109e
v2.0.50
Yuripetusko Feb 26, 2022
fcd22e3
update polkadot deps
Yuripetusko Feb 28, 2022
d684d06
v2.0.51
Yuripetusko Feb 28, 2022
4cbc9a5
Invalidate extrinsic with royalty value less than 0 and more than 100
Yuripetusko Feb 28, 2022
f3c835d
v2.0.52
Yuripetusko Feb 28, 2022
52b17a1
Convert address according to ss58Format
Yuripetusko Mar 1, 2022
8f12998
Merge branch 'master' of github.com:rmrk-team/rmrk-tools
Yuripetusko Mar 1, 2022
fd2fb88
Consolidate according to ss58Format
Yuripetusko Mar 1, 2022
97f752c
use ss58Format in listener
Yuripetusko Mar 1, 2022
a7bf516
v2.0.53
Yuripetusko Mar 1, 2022
82c7ec8
Update buy.ts
Yuripetusko Mar 1, 2022
57b95ff
Update buy.test.ts.snap
Yuripetusko Mar 1, 2022
aead82b
v2.0.54
Yuripetusko Mar 1, 2022
7c7a4ae
export all types
yornaath Mar 3, 2022
d6e634b
export all from types
yornaath Mar 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# RMRK Tools

Typescript implementation of the [RMRK spec](https://github.com/Swader/rmrk-spec/).
Typescript implementation of the [RMRK spec](https://github.com/Swader/rmrk-spec/) using Substrate's `system.remark` extrinsics.

Note that there are also [EVM](https://github.com/rmrk-team/evm) and [Substrate pallet](https://github.com/rmrk-team/rmrk-substrate) implementations of [RMRK spec](https://github.com/rmrk-team/rmrk-spec)

![Tests](https://github.com/Swader/rmrk-tools/actions/workflows/run-tests.yml/badge.svg)

Expand Down
12 changes: 9 additions & 3 deletions cli/consolidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ import { Remark } from "../src/rmrk2.0.0/tools/consolidator/remark";
const getRemarks = (
inputData: any,
prefixes: string[],
collectionFilter?: string
collectionFilter?: string,
ss58Format?: number
): Remark[] => {
let blocks = inputData;
if (collectionFilter) {
blocks = filterBlocksByCollection(blocks, prefixes, collectionFilter);
blocks = filterBlocksByCollection(
blocks,
prefixes,
collectionFilter,
ss58Format
);
}
return getRemarksFromBlocks(blocks, prefixes);
};
Expand Down Expand Up @@ -68,7 +74,7 @@ const consolidate = async () => {

console.log(`Loaded ${rawdata.length} blocks with remark calls`);

const remarks = getRemarks(rawdata, prefixes, collectionFilter);
const remarks = getRemarks(rawdata, prefixes, collectionFilter, ss58Format);
const con = new Consolidator(ss58Format);

const ret = await con.consolidate(remarks);
Expand Down
1 change: 1 addition & 0 deletions cli/run-listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const runListener = async () => {
prefixes: ["0x726d726b", "0x524d524b"],
consolidateFunction,
storageProvider,
loggerEnabled: true,
});
const subscriber = listener.initialiseObservable();
subscriber.subscribe((val) => console.log(val));
Expand Down
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rmrk-tools",
"version": "2.0.40",
"version": "2.0.54",
"description": "Suite of libraries implementing RMRK.app specs",
"repository": {
"type": "git",
Expand Down Expand Up @@ -55,11 +55,10 @@
"@babel/preset-env": "^7.13.9",
"@babel/preset-typescript": "^7.13.0",
"@pinata/sdk": "^1.1.13",
"@polkadot/api": "^7.7.1",
"@polkadot/extension-dapp": "^0.42.7",
"@polkadot/keyring": "^8.3.3",
"@polkadot/util-crypto": "^8.3.3",
"@polkadot/x-randomvalues": "^8.3.3",
"@polkadot/api": "^7.10.1",
"@polkadot/keyring": "^8.4.1",
"@polkadot/util-crypto": "^8.4.1",
"@polkadot/x-randomvalues": "^8.4.1",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-json": "^4.1.0",
Expand Down Expand Up @@ -89,7 +88,7 @@
"webpack-cli": "^4.5.0"
},
"dependencies": {
"@polkadot/api-augment": "^7.7.1",
"@polkadot/api-augment": "^7.10.1",
"JSONStream": "^1.3.5",
"chalk": "^4.1.0",
"emoji-regex": "^9.2.2",
Expand All @@ -103,7 +102,7 @@
},
"peerDependency": {
"@polkadot/api": "^7.x",
"@polkadot/extension-dapp": "^0.40.x",
"@polkadot/extension-dapp": "^0.42.x",
"@polkadot/keyring": "^7.x",
"@polkadot/util-crypto": "^7.x",
"@polkadot/util": "^7.x"
Expand Down
6 changes: 6 additions & 0 deletions src/rmrk2.0.0/changelog.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { OP_TYPES } from "./tools/constants";

export type ChangeExtraBalanceTransfer = {
receiver: string;
amount: string;
};

export type Change = {
field: string;
old: any;
new: any;
caller: string;
block: number;
opType: OP_TYPES;
extraTransfers?: ChangeExtraBalanceTransfer[];
};
15 changes: 10 additions & 5 deletions src/rmrk2.0.0/classes/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { getRemarkData } from "../tools/utils";
import { OP_TYPES, PREFIX, VERSION } from "../tools/constants";
import { BaseType } from "../tools/types";
import { Change } from "../changelog";
import { encodeAddress } from "@polkadot/keyring";

export class Base {
readonly block: number;
readonly symbol: string;
readonly type: BaseType;
readonly type?: BaseType;
readonly parts?: IBasePart[];
issuer: string;
changes: Change[] = [];
Expand All @@ -17,13 +18,13 @@ export class Base {
block: number,
symbol: string,
issuer: string,
type: BaseType,
type?: BaseType,
parts?: IBasePart[],
themes?: Record<string, Theme>
) {
this.block = block;
this.symbol = symbol;
this.type = type;
this.type = type || undefined;
this.issuer = issuer;
this.parts = parts || undefined;
this.themes = themes || undefined;
Expand Down Expand Up @@ -133,7 +134,11 @@ export class Base {
return this.changes;
}

static fromRemark(remark: string, block?: number): Base | string {
static fromRemark(
remark: string,
block?: number,
ss58Format?: number
): Base | string {
if (!block) {
block = 0;
}
Expand All @@ -144,7 +149,7 @@ export class Base {
return new this(
block,
obj.symbol,
obj.issuer,
encodeAddress(obj.issuer, ss58Format),
obj.type,
obj.parts,
obj.themes
Expand Down
13 changes: 11 additions & 2 deletions src/rmrk2.0.0/classes/changeissuer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { validateChangeIssuer } from "../tools/validate-remark";
import { isValidAddressPolkadotAddress } from "../tools/consolidator/utils";
import { encodeAddress } from "@polkadot/keyring";

export class ChangeIssuer {
issuer: string;
Expand All @@ -9,11 +11,18 @@ export class ChangeIssuer {
this.id = id;
}

static fromRemark(remark: string): ChangeIssuer | string {
static fromRemark(
remark: string,
ss58Format?: number
): ChangeIssuer | string {
try {
validateChangeIssuer(remark);
const [prefix, op_type, version, id, issuer] = remark.split("::");
return new ChangeIssuer(issuer, id);
let encodedIssuer = issuer;
if (isValidAddressPolkadotAddress(issuer)) {
encodedIssuer = encodeAddress(issuer, ss58Format);
}
return new ChangeIssuer(encodedIssuer, id);
} catch (e: any) {
console.error(e.message);
console.log(`CHANGEISSUER error: full input was ${remark}`);
Expand Down
9 changes: 7 additions & 2 deletions src/rmrk2.0.0/classes/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { validateCollection } from "../tools/validate-remark";
import { getRemarkData } from "../tools/utils";
import { OP_TYPES, PREFIX, VERSION } from "../tools/constants";
import { IProperties } from "../tools/types";
import { encodeAddress } from "@polkadot/keyring";

export class Collection {
readonly block: number;
Expand Down Expand Up @@ -98,15 +99,19 @@ export class Collection {
);
}

static fromRemark(remark: string, block = 0): Collection | string {
static fromRemark(
remark: string,
block = 0,
ss58Format?: number
): Collection | string {
try {
validateCollection(remark);
const [prefix, op_type, version, dataString] = remark.split("::");
const obj = getRemarkData(dataString);
return new this(
block,
obj.max,
obj.issuer,
encodeAddress(obj.issuer, ss58Format),
obj.symbol,
obj.id,
obj.metadata
Expand Down
17 changes: 13 additions & 4 deletions src/rmrk2.0.0/classes/nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { EMOTE_NAMESPACES } from "./emote";
import { IProperties } from "../tools/types";
import { Theme } from "./base";
import { isValidAddressPolkadotAddress } from "../tools/consolidator/utils";
import { encodeAddress } from "@polkadot/keyring";

interface INftInstanceProps {
block: number;
Expand Down Expand Up @@ -112,7 +113,11 @@ export class NFT {
return `${PREFIX}::${OP_TYPES.BURN}::${VERSION}::${id}`;
}

static fromRemark(remark: string, block?: number): NFT | string {
static fromRemark(
remark: string,
block?: number,
ss58Format?: number
): NFT | string {
if (!block) {
block = 0;
}
Expand All @@ -121,6 +126,10 @@ export class NFT {
const [prefix, op_type, version, dataString, recipient] = remark.split(
"::"
);
let recipientEncoded = recipient;
if (isValidAddressPolkadotAddress(recipient)) {
recipientEncoded = encodeAddress(recipient, ss58Format);
}
const obj = getRemarkData(dataString);
return new this({
block,
Expand All @@ -132,9 +141,9 @@ export class NFT {
: parseInt(obj.transferable, 10),
sn: obj.sn,
metadata: obj.metadata,
owner: recipient,
rootowner: isValidAddressPolkadotAddress(recipient)
? recipient
owner: recipientEncoded,
rootowner: isValidAddressPolkadotAddress(recipientEncoded)
? recipientEncoded
: undefined,
properties: obj.properties || {},
});
Expand Down
10 changes: 8 additions & 2 deletions src/rmrk2.0.0/classes/send.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { validateSend } from "../tools/validate-remark";
import { isValidAddressPolkadotAddress } from "../tools/consolidator/utils";
import { encodeAddress } from "@polkadot/keyring";

export class Send {
recipient: string;
Expand All @@ -9,11 +11,15 @@ export class Send {
this.id = id;
}

static fromRemark(remark: string): Send | string {
static fromRemark(remark: string, ss58Format?: number): Send | string {
try {
validateSend(remark);
const [_prefix, _op_type, _version, id, recipient] = remark.split("::");
return new Send(id, recipient);
let recipientEncoded = recipient;
if (isValidAddressPolkadotAddress(recipient)) {
recipientEncoded = encodeAddress(recipient, ss58Format);
}
return new Send(id, recipientEncoded);
} catch (e: any) {
console.error(e.message);
console.log(`SEND error: full input was ${remark}`);
Expand Down
33 changes: 17 additions & 16 deletions src/rmrk2.0.0/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import "@polkadot/api-augment";
export { Consolidator } from "./tools/consolidator/consolidator";
export { Collection } from "./classes/collection";
export { NFT } from "./classes/nft";
export { Base } from "./classes/base";
export { List } from "./classes/list";
export { Burn } from "./classes/burn";
export { ChangeIssuer } from "./classes/changeissuer";
export { Buy } from "./classes/buy";
export { Send } from "./classes/send";
export { Emote } from "./classes/emote";
export { Accept } from "./classes/accept";
export { Resadd } from "./classes/resadd";
export { Setproperty } from "./classes/setproperty";
export { Equip } from "./classes/equip";
export { Equippable } from "./classes/equippable";
export { Setpriority } from "./classes/setpriority";
export * from './tools/types'
export * from "./tools/consolidator/consolidator";
export * from "./classes/collection";
export * from "./classes/nft";
export * from "./classes/base";
export * from "./classes/list";
export * from "./classes/burn";
export * from "./classes/changeissuer";
export * from "./classes/buy";
export * from "./classes/send";
export * from "./classes/emote";
export * from "./classes/accept";
export * from "./classes/resadd";
export * from "./classes/setproperty";
export * from "./classes/equip";
export * from "./classes/equippable";
export * from "./classes/setpriority";
export { default as fetchRemarks } from "./tools/fetchRemarks";
export * from "./tools/consolidator/utils";
export { RemarkListener } from "./listener";
Expand Down
Loading