Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

atomicassets

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

atomicassets - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

56

build/Actions/Generator.d.ts

@@ -21,34 +21,26 @@ export declare type EosioAuthorizationObject = {

readonly contract: string;
readonly core_token: string;
readonly precision: number;
constructor(contract: string, core_token: string, precision: number);
acceptoffer(authorization: EosioAuthorizationObject[], offer_id: string): Promise<EosioActionObject>;
addcolauth(authorization: EosioAuthorizationObject[], collection_name: string, account_to_add: string): Promise<EosioActionObject>;
addnotifyacc(authorization: EosioAuthorizationObject[], collection_name: string, account_to_add: string): Promise<EosioActionObject>;
burnasset(authorization: EosioAuthorizationObject[], owner: string, asset_id: string): Promise<EosioActionObject>;
canceloffer(authorization: EosioAuthorizationObject[], offer_id: string): Promise<EosioActionObject>;
createcol(authorization: EosioAuthorizationObject[], author: string, collection_name: string, authorized_accounts: string[], notify_accounts: string[], data: AttributeMap): Promise<EosioActionObject>;
createoffer(authorization: EosioAuthorizationObject[], sender: string, recipient: string, sender_asset_ids: string[], recipient_asset_ids: string[], memo: string): Promise<EosioActionObject>;
createpre(authorization: EosioAuthorizationObject[], authorized_creator: string, scheme_name: string, collection_name: string, transferable: boolean, burnable: boolean, max_supply: string, immutable_data: AttributeMap, mutable_data: AttributeMap): Promise<EosioActionObject>;
createscheme(authorization: EosioAuthorizationObject[], author: string, scheme_name: string, scheme_format: Format[]): Promise<EosioActionObject>;
declineoffer(authorization: EosioAuthorizationObject[], offer_id: string): Promise<EosioActionObject>;
extendscheme(authorization: EosioAuthorizationObject[], scheme_name: string, scheme_format_extension: Format[]): Promise<EosioActionObject>;
mintasset(authorization: EosioAuthorizationObject[], authorized_minter: string, preset_id: string, new_owner: string, immutable_data: AttributeMap, mutable_data: AttributeMap): Promise<EosioActionObject>;
remcolauth(authorization: EosioAuthorizationObject[], collection_name: string, account_to_remove: string): Promise<EosioActionObject>;
remnotifyacc(authorization: EosioAuthorizationObject[], collection_name: string, account_to_remove: string): Promise<EosioActionObject>;
setassetdata(authorization: EosioAuthorizationObject[], authorized_editor: string, owner: string, asset_id: string, mutable_data: AttributeMap): Promise<EosioActionObject>;
setcoldata(authorization: EosioAuthorizationObject[], collection_name: string, data: AttributeMap): Promise<EosioActionObject>;
setpredata(authorization: EosioAuthorizationObject[], authorized_editor: string, preset_id: string, new_mutable_data: AttributeMap): Promise<EosioActionObject>;
transfer(authorization: EosioAuthorizationObject[], account_from: string, account_to: string, asset_ids: string[], memo: string): Promise<EosioActionObject>;
backtokens(authorization: EosioAuthorizationObject[], owner: string, asset_id: string, payer: string, quantity: string): Promise<{
account: string;
name: string;
authorization: EosioAuthorizationObject[];
data: {
from: string;
to: string;
quantity: string;
};
}>;
protected _pack(authorization: EosioAuthorizationObject[], name: string, data: any): EosioActionObject;
constructor(contract: string);
acceptoffer(authorization: EosioAuthorizationObject[], offer_id: string): Promise<EosioActionObject[]>;
addcolauth(authorization: EosioAuthorizationObject[], collection_name: string, account_to_add: string): Promise<EosioActionObject[]>;
addconftoken(authorization: EosioAuthorizationObject[], token_contract: string, token_symbol: string): Promise<EosioActionObject[]>;
addnotifyacc(authorization: EosioAuthorizationObject[], collection_name: string, account_to_add: string): Promise<EosioActionObject[]>;
admincoledit(authorization: EosioAuthorizationObject[], collection_format_extension: Format[]): Promise<EosioActionObject[]>;
backsymbol(authorization: EosioAuthorizationObject[], ram_payer: string, owner: string, asset_id: string, symbol_to_announce: string, token_contract: string, quantity: string): Promise<EosioActionObject[]>;
burnasset(authorization: EosioAuthorizationObject[], owner: string, asset_id: string): Promise<EosioActionObject[]>;
canceloffer(authorization: EosioAuthorizationObject[], offer_id: string): Promise<EosioActionObject[]>;
createcol(authorization: EosioAuthorizationObject[], author: string, collection_name: string, allow_notify: boolean, authorized_accounts: string[], notify_accounts: string[], market_fee: number, data: AttributeMap): Promise<EosioActionObject[]>;
createoffer(authorization: EosioAuthorizationObject[], sender: string, recipient: string, sender_asset_ids: string[], recipient_asset_ids: string[], memo: string): Promise<EosioActionObject[]>;
createpreset(authorization: EosioAuthorizationObject[], authorized_creator: string, collection_name: string, scheme_name: string, transferable: boolean, burnable: boolean, max_supply: string, immutable_data: AttributeMap): Promise<EosioActionObject[]>;
createscheme(authorization: EosioAuthorizationObject[], authorized_creator: string, collection_name: string, scheme_name: string, scheme_format: Format[]): Promise<EosioActionObject[]>;
declineoffer(authorization: EosioAuthorizationObject[], offer_id: string): Promise<EosioActionObject[]>;
extendscheme(authorization: EosioAuthorizationObject[], authorized_editor: string, collection_name: string, scheme_name: string, scheme_format_extension: Format[]): Promise<EosioActionObject[]>;
forbidnotify(authorization: EosioAuthorizationObject[], collection_name: string): Promise<EosioActionObject[]>;
mintasset(authorization: EosioAuthorizationObject[], authorized_minter: string, collection_name: string, scheme_name: string, preset_id: string, new_owner: string, immutable_data: AttributeMap, mutable_data: AttributeMap): Promise<EosioActionObject[]>;
remcolauth(authorization: EosioAuthorizationObject[], collection_name: string, account_to_remove: string): Promise<EosioActionObject[]>;
remnotifyacc(authorization: EosioAuthorizationObject[], collection_name: string, account_to_remove: string): Promise<EosioActionObject[]>;
setassetdata(authorization: EosioAuthorizationObject[], authorized_editor: string, owner: string, asset_id: string, new_mutable_data: AttributeMap): Promise<EosioActionObject[]>;
setcoldata(authorization: EosioAuthorizationObject[], collection_name: string, data: AttributeMap): Promise<EosioActionObject[]>;
setmarketfee(authorization: EosioAuthorizationObject[], collection_name: string, market_fee: number): Promise<EosioActionObject[]>;
transfer(authorization: EosioAuthorizationObject[], account_from: string, account_to: string, asset_ids: string[], memo: string): Promise<EosioActionObject[]>;
protected _pack(authorization: EosioAuthorizationObject[], name: string, data: any): EosioActionObject[];
}

@@ -5,6 +5,4 @@ "use strict";

class ActionGenerator {
constructor(contract, core_token, precision) {
constructor(contract) {
this.contract = contract;
this.core_token = core_token;
this.precision = precision;
}

@@ -17,5 +15,21 @@ async acceptoffer(authorization, offer_id) {

}
async addconftoken(authorization, token_contract, token_symbol) {
return this._pack(authorization, "addconftoken", { token_contract, token_symbol });
}
async addnotifyacc(authorization, collection_name, account_to_add) {
return this._pack(authorization, "addnotifyacc", { collection_name, account_to_add });
}
async admincoledit(authorization, collection_format_extension) {
return this._pack(authorization, "admincoledit", { collection_format_extension });
}
async backsymbol(authorization, ram_payer, owner, asset_id, symbol_to_announce, token_contract, quantity) {
const actions = this._pack(authorization, "backsymbol", { ram_payer, owner, asset_id, symbol_to_announce });
actions.push({
account: token_contract,
name: "transfer",
authorization,
data: { from: ram_payer, to: this.contract, quantity: quantity + " " + symbol_to_announce },
});
return actions;
}
async burnasset(authorization, owner, asset_id) {

@@ -27,4 +41,4 @@ return this._pack(authorization, "burnasset", { owner, asset_id });

}
async createcol(authorization, author, collection_name, authorized_accounts, notify_accounts, data) {
return this._pack(authorization, "createcol", { author, collection_name, authorized_accounts, notify_accounts, data });
async createcol(authorization, author, collection_name, allow_notify, authorized_accounts, notify_accounts, market_fee, data) {
return this._pack(authorization, "createcol", { author, collection_name, allow_notify, authorized_accounts, notify_accounts, market_fee, data });
}

@@ -34,9 +48,9 @@ async createoffer(authorization, sender, recipient, sender_asset_ids, recipient_asset_ids, memo) {

}
async createpre(authorization, authorized_creator, scheme_name, collection_name, transferable, burnable, max_supply, immutable_data, mutable_data) {
return this._pack(authorization, "createpre", {
authorized_creator, scheme_name, collection_name, transferable, burnable, max_supply, immutable_data, mutable_data,
async createpreset(authorization, authorized_creator, collection_name, scheme_name, transferable, burnable, max_supply, immutable_data) {
return this._pack(authorization, "createpreset", {
authorized_creator, collection_name, scheme_name, transferable, burnable, max_supply, immutable_data,
});
}
async createscheme(authorization, author, scheme_name, scheme_format) {
return this._pack(authorization, "createscheme", { scheme_name, scheme_format });
async createscheme(authorization, authorized_creator, collection_name, scheme_name, scheme_format) {
return this._pack(authorization, "createscheme", { authorized_creator, collection_name, scheme_name, scheme_format });
}

@@ -46,8 +60,11 @@ async declineoffer(authorization, offer_id) {

}
async extendscheme(authorization, scheme_name, scheme_format_extension) {
return this._pack(authorization, "extendscheme", { scheme_name, scheme_format_extension });
async extendscheme(authorization, authorized_editor, collection_name, scheme_name, scheme_format_extension) {
return this._pack(authorization, "extendscheme", { authorized_editor, collection_name, scheme_name, scheme_format_extension });
}
async mintasset(authorization, authorized_minter, preset_id, new_owner, immutable_data, mutable_data) {
return this._pack(authorization, "mintasset", { authorized_minter, preset_id, new_owner, immutable_data, mutable_data });
async forbidnotify(authorization, collection_name) {
return this._pack(authorization, "forbidnotify", { collection_name });
}
async mintasset(authorization, authorized_minter, collection_name, scheme_name, preset_id, new_owner, immutable_data, mutable_data) {
return this._pack(authorization, "mintasset", { authorized_minter, collection_name, scheme_name, preset_id, new_owner, immutable_data, mutable_data });
}
async remcolauth(authorization, collection_name, account_to_remove) {

@@ -59,4 +76,4 @@ return this._pack(authorization, "remcolauth", { collection_name, account_to_remove });

}
async setassetdata(authorization, authorized_editor, owner, asset_id, mutable_data) {
return this._pack(authorization, "setassetdata", { authorized_editor, owner, asset_id, mutable_data });
async setassetdata(authorization, authorized_editor, owner, asset_id, new_mutable_data) {
return this._pack(authorization, "setassetdata", { authorized_editor, owner, asset_id, new_mutable_data });
}

@@ -66,4 +83,4 @@ async setcoldata(authorization, collection_name, data) {

}
async setpredata(authorization, authorized_editor, preset_id, new_mutable_data) {
return this._pack(authorization, "setpredata", { authorized_editor, preset_id, new_mutable_data });
async setmarketfee(authorization, collection_name, market_fee) {
return this._pack(authorization, "setmarketfee", { collection_name, market_fee });
}

@@ -73,14 +90,6 @@ async transfer(authorization, account_from, account_to, asset_ids, memo) {

}
async backtokens(authorization, owner, asset_id, payer, quantity) {
return {
account: "eosio.token",
name: "transfer",
authorization,
data: { from: payer, to: this.contract, quantity },
};
}
_pack(authorization, name, data) {
return { account: this.contract, name, authorization, data };
return [{ account: this.contract, name, authorization, data }];
}
}
exports.default = ActionGenerator;
import RpcApi from "../API/Rpc";
import ActionGenerator, { AttributeMap, EosioAuthorizationObject } from "./Generator";
import ActionGenerator, { EosioAuthorizationObject } from "./Generator";
export default class RpcActionGenerator extends ActionGenerator {

@@ -7,8 +7,7 @@ readonly api: RpcApi;

constructor(api: RpcApi);
createcol(authorization: EosioAuthorizationObject[], author: string, collection_name: string, authorized_accounts: string[], notify_accounts: string[], data: object): Promise<import("./Generator").EosioActionObject>;
createpre(authorization: EosioAuthorizationObject[], authorized_creator: string, scheme_name: string, collection_name: string, transferable: boolean, burnable: boolean, max_supply: string, immutable_data: object, mutable_data: object): Promise<import("./Generator").EosioActionObject>;
mintasset(authorization: EosioAuthorizationObject[], authorized_minter: string, preset_id: string, new_owner: string, immutable_data: object, mutable_data: object): Promise<import("./Generator").EosioActionObject>;
setassetdata(authorization: EosioAuthorizationObject[], authorized_editor: string, owner: string, asset_id: string, mutable_data: object): Promise<import("./Generator").EosioActionObject>;
setcoldata(authorization: EosioAuthorizationObject[], collection_name: string, data: object): Promise<import("./Generator").EosioActionObject>;
setpredata(authorization: EosioAuthorizationObject[], authorized_editor: string, preset_id: string, new_mutable_data: AttributeMap): Promise<import("./Generator").EosioActionObject>;
createcol(authorization: EosioAuthorizationObject[], author: string, collection_name: string, allow_notify: boolean, authorized_accounts: string[], notify_accounts: string[], market_fee: number, data: object): Promise<import("./Generator").EosioActionObject[]>;
createpreset(authorization: EosioAuthorizationObject[], authorized_creator: string, collection_name: string, scheme_name: string, transferable: boolean, burnable: boolean, max_supply: string, immutable_data: object): Promise<import("./Generator").EosioActionObject[]>;
mintasset(authorization: EosioAuthorizationObject[], authorized_minter: string, collection_name: string, scheme_name: string, preset_id: string, new_owner: string, immutable_data: object, mutable_data: object): Promise<import("./Generator").EosioActionObject[]>;
setassetdata(authorization: EosioAuthorizationObject[], authorized_editor: string, owner: string, asset_id: string, mutable_data: object): Promise<import("./Generator").EosioActionObject[]>;
setcoldata(authorization: EosioAuthorizationObject[], collection_name: string, data: object): Promise<import("./Generator").EosioActionObject[]>;
}

@@ -11,3 +11,3 @@ "use strict";

constructor(api) {
super(api.contract, api.coreToken, api.precision);
super(api.contract);
this.api = api;

@@ -30,23 +30,22 @@ }

}
async createcol(authorization, author, collection_name, authorized_accounts, notify_accounts, data) {
async createcol(authorization, author, collection_name, allow_notify, authorized_accounts, notify_accounts, market_fee, data) {
const config = await this.api.config();
return super.createcol(authorization, author, collection_name, authorized_accounts, notify_accounts, RpcActionGenerator.toAttributeMap(data, config.collection_format));
return super.createcol(authorization, author, collection_name, allow_notify, authorized_accounts, notify_accounts, market_fee, RpcActionGenerator.toAttributeMap(data, config.collection_format));
}
async createpre(authorization, authorized_creator, scheme_name, collection_name, transferable, burnable, max_supply, immutable_data, mutable_data) {
const scheme = await this.api.getScheme(scheme_name);
const idata = RpcActionGenerator.toAttributeMap(immutable_data, await scheme.rawFormat());
const mdata = RpcActionGenerator.toAttributeMap(mutable_data, await scheme.rawFormat());
return super.createpre(authorization, authorized_creator, scheme_name, collection_name, transferable, burnable, max_supply, idata, mdata);
async createpreset(authorization, authorized_creator, collection_name, scheme_name, transferable, burnable, max_supply, immutable_data) {
const scheme = await this.api.getScheme(collection_name, scheme_name);
const immutable_attribute_map = RpcActionGenerator.toAttributeMap(immutable_data, await scheme.rawFormat());
return super.createpreset(authorization, authorized_creator, collection_name, scheme_name, transferable, burnable, max_supply, immutable_attribute_map);
}
async mintasset(authorization, authorized_minter, preset_id, new_owner, immutable_data, mutable_data) {
async mintasset(authorization, authorized_minter, collection_name, scheme_name, preset_id, new_owner, immutable_data, mutable_data) {
const preset = await this.api.getPreset(preset_id);
const idata = RpcActionGenerator.toAttributeMap(immutable_data, await (await preset.scheme()).rawFormat());
const mdata = RpcActionGenerator.toAttributeMap(mutable_data, await (await preset.scheme()).rawFormat());
return super.mintasset(authorization, authorized_minter, preset_id, new_owner, idata, mdata);
const immutable_attribute_map = RpcActionGenerator.toAttributeMap(immutable_data, await (await preset.scheme()).rawFormat());
const mutable_attribute_map = RpcActionGenerator.toAttributeMap(mutable_data, await (await preset.scheme()).rawFormat());
return super.mintasset(authorization, authorized_minter, collection_name, scheme_name, preset_id, new_owner, immutable_attribute_map, mutable_attribute_map);
}
async setassetdata(authorization, authorized_editor, owner, asset_id, mutable_data) {
const asset = await this.api.getAsset(owner, asset_id);
const scheme = await (await asset.preset()).scheme();
const mdata = RpcActionGenerator.toAttributeMap(mutable_data, await scheme.rawFormat());
return super.setassetdata(authorization, authorized_editor, owner, asset_id, mdata);
const scheme = await asset.scheme();
const mutable_attribute_map = RpcActionGenerator.toAttributeMap(mutable_data, await scheme.rawFormat());
return super.setassetdata(authorization, authorized_editor, owner, asset_id, mutable_attribute_map);
}

@@ -57,8 +56,3 @@ async setcoldata(authorization, collection_name, data) {

}
async setpredata(authorization, authorized_editor, preset_id, new_mutable_data) {
const preset = await this.api.getPreset(preset_id);
const mdata = RpcActionGenerator.toAttributeMap(new_mutable_data, await (await preset.scheme()).rawFormat());
return super.setpredata(authorization, authorized_editor, preset_id, mdata);
}
}
exports.default = RpcActionGenerator;

@@ -1,4 +0,6 @@

import { AssetRow } from "./Cache";
import { IAssetRow } from "./Cache";
import RpcCollection from "./Collection";
import RpcApi from "./index";
import RpcPreset from "./Preset";
import RpcScheme from "./Scheme";
export default class RpcAsset {

@@ -9,9 +11,13 @@ private readonly api;

private readonly _preset;
constructor(api: RpcApi, owner: string, id: string, data?: AssetRow, preset?: RpcPreset, cache?: boolean);
preset(): Promise<RpcPreset>;
backedTokens(): Promise<string>;
immutableData(): Promise<object | string>;
mutableData(): Promise<object | string>;
private readonly _collection;
private readonly _scheme;
constructor(api: RpcApi, owner: string, id: string, data?: IAssetRow, collection?: RpcCollection, scheme?: RpcScheme, preset?: RpcPreset, cache?: boolean);
preset(): Promise<RpcPreset | null>;
collection(): Promise<RpcCollection>;
scheme(): Promise<RpcScheme>;
backedTokens(): Promise<string[]>;
immutableData(): Promise<object>;
mutableData(): Promise<object>;
data(): Promise<object>;
toObject(): Promise<object>;
}

@@ -6,7 +6,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const big_integer_1 = __importDefault(require("big-integer"));
const Serialization_1 = require("../../Serialization");
const Collection_1 = __importDefault(require("./Collection"));
const Preset_1 = __importDefault(require("./Preset"));
const Scheme_1 = __importDefault(require("./Scheme"));
class RpcAsset {
constructor(api, owner, id, data, preset, cache = true) {
constructor(api, owner, id, data, collection, scheme, preset, cache = true) {
this.api = api;

@@ -34,2 +35,5 @@ this.id = id;

const row = await this._data;
if (Number(row.preset_id) < 0) {
return resolve(null);
}
resolve(new Preset_1.default(api, row.preset_id, undefined, undefined, undefined, cache));

@@ -42,2 +46,30 @@ }

});
this._collection = new Promise(async (resolve, reject) => {
if (collection) {
resolve(collection);
}
else {
try {
const row = await this._data;
resolve(new Collection_1.default(api, row.collection_name, undefined, cache));
}
catch (e) {
reject(e);
}
}
});
this._scheme = new Promise(async (resolve, reject) => {
if (scheme) {
resolve(scheme);
}
else {
try {
const row = await this._data;
resolve(new Scheme_1.default(api, row.collection_name, row.scheme_name, undefined, cache));
}
catch (e) {
reject(e);
}
}
});
}

@@ -47,18 +79,20 @@ async preset() {

}
async collection() {
return await this._collection;
}
async scheme() {
return await this._scheme;
}
async backedTokens() {
return big_integer_1.default((await this._data).backed_core_amount).divide(this.api.precision).toString();
return (await this._data).backed_tokens;
}
async immutableData() {
const preset = await this.preset();
const scheme = await preset.scheme();
const data = await this._data;
const pdata = await preset.immutableData();
return Object.assign({}, pdata, Serialization_1.deserialize(data.immutable_serialized_data, await scheme.format()));
const scheme = await this.scheme();
const row = await this._data;
return Serialization_1.deserialize(row.immutable_serialized_data, await scheme.format());
}
async mutableData() {
const preset = await this.preset();
const scheme = await preset.scheme();
const data = await this._data;
const pdata = await preset.mutableData();
return Object.assign({}, pdata, Serialization_1.deserialize(data.mutable_serialized_data, await scheme.format()));
const scheme = await this.scheme();
const row = await this._data;
return Serialization_1.deserialize(row.mutable_serialized_data, await scheme.format());
}

@@ -68,11 +102,19 @@ async data() {

const immutableData = await this.immutableData();
return Object.assign({}, mutableData, immutableData);
const preset = await this.preset();
const presetData = preset ? await preset.immutableData() : {};
return Object.assign({}, mutableData, immutableData, presetData);
}
async toObject() {
const preset = await this.preset();
const collection = await this.collection();
const scheme = await this.scheme();
return {
id: this.id,
asset_id: this.id,
collection: await collection.toObject(),
scheme: await scheme.toObject(),
preset: preset ? await preset.toObject() : null,
backedTokens: await this.backedTokens(),
immutableData: await this.immutableData(),
mutableData: await this.mutableData(),
preset: await (await this.preset()).toObject(),
data: await this.data(),
};

@@ -79,0 +121,0 @@ }

@@ -5,13 +5,19 @@ export declare type SchemeFormat = Array<{

}>;
export declare type AssetRow = {
id: string;
preset_id: string;
ram_payer: string;
backed_core_amount: string;
immutable_serialized_data: Uint8Array;
mutable_serialized_data: Uint8Array;
};
export declare type PresetRow = {
export interface ICollectionRow {
collection_name: string;
author: string;
allow_notify: boolean;
authorized_accounts: string[];
notify_accounts: string[];
market_fee: number;
serialized_data: Uint8Array;
}
export interface ISchemeRow {
scheme_name: string;
format: SchemeFormat;
}
export interface IPresetRow {
preset_id: number;
collection_name: string;
scheme_name: string;
transferable: boolean;

@@ -21,19 +27,16 @@ burnable: boolean;

issued_supply: number;
mutable_serialized_data: Uint8Array;
immutable_serialized_data: Uint8Array;
};
export declare type SchemeRow = {
}
export interface IAssetRow {
asset_id: string;
collection_name: string;
scheme_name: string;
author: string;
format: SchemeFormat;
};
export declare type CollectionRow = {
collection_name: string;
author: string;
authorized_accounts: string[];
notify_accounts: string[];
serialized_data: Uint8Array;
};
export declare type OfferRow = {
id: string;
preset_id: string;
ram_payer: string;
backed_tokens: string[];
immutable_serialized_data: Uint8Array;
mutable_serialized_data: Uint8Array;
}
export interface IOfferRow {
offer_id: string;
offer_sender: string;

@@ -44,8 +47,10 @@ offer_recipient: string;

memo: string;
};
export declare type ConfigRow = {
}
export interface IConfigRow {
asset_counter: string;
offer_counter: string;
collection_format: SchemeFormat;
};
}
export default class RpcCache {
private static access;
private readonly assets;

@@ -56,8 +61,7 @@ private readonly presets;

private readonly offers;
asset(assetID: string, data?: any | null | false): AssetRow | undefined;
preset(presetID: string, data?: any | null | false): PresetRow | undefined;
scheme(scheme: string, data?: any | null | false): SchemeRow | undefined;
collection(collection: string, data?: any | null | false): CollectionRow | undefined;
offer(offerID: string, data?: any | null | false): OfferRow | undefined;
private access;
asset(assetID: string, data?: any | null | false): IAssetRow | undefined;
preset(presetID: string, data?: any | null | false): IPresetRow | undefined;
scheme(scheme: string, data?: any | null | false): ISchemeRow | undefined;
collection(collection: string, data?: any | null | false): ICollectionRow | undefined;
offer(offerID: string, data?: any | null | false): IOfferRow | undefined;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Binary_1 = require("../../Serialization/Binary");
class RpcCache {

@@ -12,2 +11,20 @@ constructor() {

}
static access(identifier, cache, data) {
if (data === null) {
delete cache[String(identifier)];
return undefined;
}
if (data) {
cache[String(identifier)] = { expiration: Date.now() + 15 * 60 * 1000, updated: Date.now(), data };
return data;
}
if (typeof cache[String(identifier)] === "undefined" || cache[String(identifier)].expiration < Date.now()) {
return undefined;
}
// if data is false then only return cache if it is not older than 5 seconds
if (data === false && Date.now() - cache[String(identifier)].updated > 5 * 1000) {
return undefined;
}
return cache[String(identifier)].data;
}
asset(assetID, data) {

@@ -18,41 +35,20 @@ if (data) {

}
return this.access(assetID, this.assets, data);
return RpcCache.access(assetID, this.assets, data);
}
preset(presetID, data) {
if (data) {
data.mutable_serialized_data = new Uint8Array(data.mutable_serialized_data);
data.immutable_serialized_data = new Uint8Array(data.immutable_serialized_data);
data.max_supply = Binary_1.byte_vector_to_int(new Uint8Array(data.max_supply));
data.issued_supply = Binary_1.byte_vector_to_int(new Uint8Array(data.issued_supply));
}
return this.access(presetID, this.presets, data);
return RpcCache.access(presetID, this.presets, data);
}
scheme(scheme, data) {
return this.access(scheme, this.schemes, data);
return RpcCache.access(scheme, this.schemes, data);
}
collection(collection, data) {
return this.access(collection, this.collections, data);
return RpcCache.access(collection, this.collections, data);
}
offer(offerID, data) {
return this.access(offerID, this.offers, data);
return RpcCache.access(offerID, this.offers, data);
}
access(identifier, cache, data) {
if (data === null) {
delete cache[String(identifier)];
return undefined;
}
if (data) {
cache[String(identifier)] = { expiration: Date.now() + 15 * 60 * 1000, updated: Date.now(), data };
return data;
}
if (typeof cache[String(identifier)] === "undefined" || cache[String(identifier)].expiration < Date.now()) {
return undefined;
}
// if data is false then only return cache if it is not older than 5 seconds
if (data === false && Date.now() - cache[String(identifier)].updated > 5 * 1000) {
return undefined;
}
return cache[String(identifier)].data;
}
}
exports.default = RpcCache;

@@ -1,2 +0,2 @@

import { CollectionRow } from "./Cache";
import { ICollectionRow } from "./Cache";
import RpcApi from "./index";

@@ -7,8 +7,10 @@ export default class RpcCollection {

private readonly _data;
constructor(api: RpcApi, name: string, data?: CollectionRow, cache?: boolean);
constructor(api: RpcApi, name: string, data?: ICollectionRow, cache?: boolean);
author(): Promise<string>;
allowNotify(): Promise<boolean>;
authorizedAccounts(): Promise<string[]>;
notifyAccounts(): Promise<string[]>;
marketFee(): Promise<number>;
data(): Promise<any>;
toObject(): Promise<object>;
}

@@ -26,2 +26,5 @@ "use strict";

}
async allowNotify() {
return !!(await this._data).allow_notify;
}
async authorizedAccounts() {

@@ -33,2 +36,5 @@ return (await this._data).authorized_accounts;

}
async marketFee() {
return Number((await this._data).market_fee);
}
async data() {

@@ -39,5 +45,8 @@ return Serialization_1.deserialize((await this._data).serialized_data, Schema_1.ObjectSchema((await this.api.config()).collection_format));

return {
collection_name: this.name,
author: await this.author(),
allowNotify: await this.allowNotify(),
authorizedAccounts: await this.authorizedAccounts(),
notifyAccounts: await this.notifyAccounts(),
marketFee: await this.marketFee(),
data: await this.data(),

@@ -44,0 +53,0 @@ };

import ActionGenerator from "../../Actions/Generator";
import RpcAsset from "./Asset";
import RpcCache, { ConfigRow } from "./Cache";
import RpcCache, { IConfigRow } from "./Cache";
import RpcCollection from "./Collection";

@@ -20,12 +20,10 @@ import RpcOffer from "./Offer";

readonly contract: string;
readonly coreToken: string;
readonly precision: number;
private readonly fetchBuiltin;
private readonly _config;
constructor(endpoint: string, contract: string, coreToken: string, precision: number, args?: ApiArgs);
config(): Promise<ConfigRow>;
constructor(endpoint: string, contract: string, args?: ApiArgs);
config(): Promise<IConfigRow>;
getAsset(owner: string, id: string, cache?: boolean): Promise<RpcAsset>;
getPreset(id: string, cache?: boolean): Promise<RpcPreset>;
getCollection(name: string, cache?: boolean): Promise<RpcCollection>;
getScheme(name: string, cache?: boolean): Promise<RpcScheme>;
getScheme(collection: string, name: string, cache?: boolean): Promise<RpcScheme>;
getOffer(id: string, cache?: boolean): Promise<RpcOffer>;

@@ -32,0 +30,0 @@ getAccountOffers(account: string, cache?: boolean): Promise<RpcOffer[]>;

@@ -16,7 +16,5 @@ "use strict";

class RpcApi {
constructor(endpoint, contract, coreToken, precision, args = { rateLimit: 4 }) {
constructor(endpoint, contract, args = { rateLimit: 4 }) {
this.endpoint = endpoint;
this.contract = contract;
this.coreToken = coreToken;
this.precision = precision;
if (args.fetch) {

@@ -53,3 +51,3 @@ this.fetchBuiltin = args.fetch;

}
return new Asset_1.default(this, owner, id, undefined, undefined, cache);
return new Asset_1.default(this, owner, id, undefined, undefined, undefined, undefined, cache);
}

@@ -68,7 +66,7 @@ async getPreset(id, cache = true) {

}
async getScheme(name, cache = true) {
async getScheme(collection, name, cache = true) {
if (!cache) {
this.cache.scheme(name, null);
}
return new Scheme_1.default(this, name, undefined, cache);
return new Scheme_1.default(this, collection, name, undefined, cache);
}

@@ -82,9 +80,9 @@ async getOffer(id, cache = true) {

async getAccountOffers(account, cache = true) {
return (await this.queue.account_offers(account)).map((offer) => {
return new Offer_1.default(this, offer.id, offer, undefined, undefined, cache);
return (await this.queue.account_offers(account)).map((offerRow) => {
return new Offer_1.default(this, offerRow.offer_id, offerRow, undefined, undefined, cache);
});
}
async getAccountAssets(account, cache = true) {
return (await this.queue.account_assets(account)).map((asset) => {
return new Asset_1.default(this, account, asset.id, asset, undefined, cache);
return (await this.queue.account_assets(account)).map((assetRow) => {
return new Asset_1.default(this, account, assetRow.asset_id, assetRow, undefined, undefined, undefined, cache);
});

@@ -91,0 +89,0 @@ }

import RpcAsset from "./Asset";
import { OfferRow } from "./Cache";
import { IOfferRow } from "./Cache";
import RpcApi from "./index";

@@ -10,9 +10,9 @@ export default class RpcOffer {

private readonly _recipientAssets;
constructor(api: RpcApi, id: string, data?: OfferRow, senderAssets?: RpcAsset[], receiverAssets?: RpcAsset[], cache?: boolean);
constructor(api: RpcApi, id: string, data?: IOfferRow, senderAssets?: RpcAsset[], receiverAssets?: RpcAsset[], cache?: boolean);
sender(): Promise<string>;
recipient(): Promise<string>;
senderAssets(): Promise<RpcAsset[]>;
recipientAssets(): Promise<RpcAsset[]>;
senderAssets(): Promise<Array<RpcAsset | string>>;
recipientAssets(): Promise<Array<RpcAsset | string>>;
memo(): Promise<string>;
toObject(): Promise<object>;
}

@@ -32,9 +32,6 @@ "use strict";

const inventory = await this.api.queue.account_assets(row.offer_sender, cache);
const offerAssets = inventory.filter((element) => {
return row.sender_asset_ids.indexOf(element.id) >= 0;
});
if (offerAssets.length !== row.sender_asset_ids.length) {
return reject(new Error("user does not own all items anymore"));
}
return resolve(offerAssets.map((asset) => new Asset_1.default(this.api, row.offer_sender, asset.id, asset)));
return resolve(row.sender_asset_ids.map((assetID) => {
const asset = inventory.find((assetRow) => assetRow.asset_id === assetID);
return asset ? new Asset_1.default(this.api, row.offer_sender, assetID, asset, undefined, undefined, undefined, cache) : assetID;
}));
}

@@ -54,9 +51,6 @@ catch (e) {

const inventory = await this.api.queue.account_assets(row.offer_recipient, cache);
const offerAssets = inventory.filter((element) => {
return row.recipient_asset_ids.indexOf(element.id) >= 0;
});
if (offerAssets.length !== row.recipient_asset_ids.length) {
return reject(new Error("user does not own all items anymore"));
}
return resolve(offerAssets.map((asset) => new Asset_1.default(this.api, row.offer_recipient, asset.id, asset)));
return resolve(row.recipient_asset_ids.map((assetID) => {
const asset = inventory.find((assetRow) => assetRow.asset_id === assetID);
return asset ? new Asset_1.default(this.api, row.offer_recipient, assetID, asset, undefined, undefined, undefined, cache) : assetID;
}));
}

@@ -86,10 +80,10 @@ catch (e) {

return {
id: this.id,
offer_id: this.id,
sender: {
account: await this.sender(),
assets: await Promise.all((await this.senderAssets()).map(async (asset) => await asset.toObject())),
assets: await Promise.all((await this.senderAssets()).map(async (asset) => typeof asset === "string" ? asset : await asset.toObject())),
},
recipient: {
account: await this.recipient(),
assets: await Promise.all((await this.recipientAssets()).map(async (asset) => await asset.toObject())),
assets: await Promise.all((await this.recipientAssets()).map(async (asset) => typeof asset === "string" ? asset : await asset.toObject())),
},

@@ -96,0 +90,0 @@ memo: await this.memo(),

@@ -1,2 +0,2 @@

import { PresetRow } from "./Cache";
import { IPresetRow } from "./Cache";
import RpcCollection from "./Collection";

@@ -11,7 +11,6 @@ import RpcApi from "./index";

private readonly _scheme;
constructor(api: RpcApi, id: string, data?: PresetRow, scheme?: RpcScheme, collection?: RpcCollection, cache?: boolean);
constructor(api: RpcApi, id: string, data?: IPresetRow, scheme?: RpcScheme, collection?: RpcCollection, cache?: boolean);
collection(): Promise<RpcCollection>;
scheme(): Promise<RpcScheme>;
immutableData(): Promise<object>;
mutableData(): Promise<object>;
isTransferable(): Promise<boolean>;

@@ -18,0 +17,0 @@ isBurnable(): Promise<boolean>;

@@ -33,3 +33,3 @@ "use strict";

const row = await this._data;
resolve(new Scheme_1.default(this.api, row.scheme_name, undefined, cache));
resolve(new Scheme_1.default(this.api, row.collection_name, row.scheme_name, undefined, cache));
}

@@ -66,6 +66,2 @@ catch (e) {

}
async mutableData() {
const scheme = await this._scheme;
return Serialization_1.deserialize((await this._data).mutable_serialized_data, await scheme.format());
}
async isTransferable() {

@@ -85,7 +81,6 @@ return !!(await this._data).transferable;

return {
id: this.id,
preset_id: this.id,
collection: await (await this.collection()).toObject(),
scheme: await (await this.scheme()).toObject(),
immutableData: await this.immutableData(),
mutableData: await this.mutableData(),
transferable: await this.isTransferable(),

@@ -92,0 +87,0 @@ burnable: await this.isBurnable(),

@@ -1,2 +0,2 @@

import { AssetRow, CollectionRow, OfferRow, PresetRow, SchemeRow } from "./Cache";
import { IAssetRow, ICollectionRow, IOfferRow, IPresetRow, ISchemeRow } from "./Cache";
import RpcApi from "./index";

@@ -9,9 +9,9 @@ export default class RpcQueue {

constructor(api: RpcApi, requestLimit?: number);
asset(owner: string, id: string, useCache?: boolean): Promise<AssetRow>;
account_assets(account: string, useCache?: boolean): Promise<AssetRow[]>;
preset(id: string, useCache?: boolean): Promise<PresetRow>;
scheme(name: string, useCache?: boolean): Promise<SchemeRow>;
collection(name: string, useCache?: boolean): Promise<CollectionRow>;
offer(id: string, useCache?: boolean): Promise<OfferRow>;
account_offers(account: string, useCache?: boolean): Promise<OfferRow[]>;
asset(owner: string, id: string, useCache?: boolean): Promise<IAssetRow>;
account_assets(account: string, useCache?: boolean): Promise<IAssetRow[]>;
preset(id: string, useCache?: boolean): Promise<IPresetRow>;
scheme(collection: string, name: string, useCache?: boolean): Promise<ISchemeRow>;
collection(name: string, useCache?: boolean): Promise<ICollectionRow>;
offer(id: string, useCache?: boolean): Promise<IOfferRow>;
account_offers(account: string, useCache?: boolean): Promise<IOfferRow[]>;
private dequeue;

@@ -18,0 +18,0 @@ private fetch_single_row;

@@ -23,4 +23,4 @@ "use strict";

}
async scheme(name, useCache = true) {
return this.fetch_single_row(this.api.contract, "schemes", name, this.api.cache.scheme.bind(this.api.cache), useCache);
async scheme(collection, name, useCache = true) {
return this.fetch_single_row(collection, "schemes", name, this.api.cache.scheme.bind(this.api.cache), useCache);
}

@@ -27,0 +27,0 @@ async collection(name, useCache = true) {

import { ISchema } from "../../Schema";
import { SchemeRow } from "./Cache";
import { ISchemeRow } from "./Cache";
import RpcApi from "./index";

@@ -8,4 +8,3 @@ export default class RpcScheme {

private readonly _data;
constructor(api: RpcApi, name: string, data?: SchemeRow, cache?: boolean);
author(): Promise<string>;
constructor(api: RpcApi, collection: string, name: string, data?: ISchemeRow, cache?: boolean);
format(): Promise<ISchema>;

@@ -17,3 +16,3 @@ rawFormat(): Promise<{

toObject(): Promise<{
author: string;
scheme_name: string;
format: {

@@ -20,0 +19,0 @@ name: string;

@@ -5,3 +5,3 @@ "use strict";

class RpcScheme {
constructor(api, name, data, cache = true) {
constructor(api, collection, name, data, cache = true) {
this.api = api;

@@ -15,3 +15,3 @@ this.name = name;

try {
resolve(await api.queue.scheme(name, cache));
resolve(await api.queue.scheme(collection, name, cache));
}

@@ -24,5 +24,2 @@ catch (e) {

}
async author() {
return (await this._data).author;
}
async format() {

@@ -36,3 +33,3 @@ return Schema_1.ObjectSchema((await this._data).format);

return {
author: await this.author(),
scheme_name: this.name,
format: (await this._data).format,

@@ -39,0 +36,0 @@ };

@@ -5,2 +5,3 @@ import ExplorerApi from "./API/Explorer";

import { deserialize, serialize } from "./Serialization";
export { RpcApi, ExplorerApi, ObjectSchema, deserialize, serialize };
import { ParserTypes } from "./Serialization/Types";
export { RpcApi, ExplorerApi, ObjectSchema, deserialize, serialize, ParserTypes };

@@ -15,1 +15,3 @@ "use strict";

exports.serialize = Serialization_1.serialize;
const Types_1 = require("./Serialization/Types");
exports.ParserTypes = Types_1.ParserTypes;

@@ -12,3 +12,3 @@ {

"license": "MIT",
"version": "0.3.0",
"version": "0.4.0",
"main": "build/index.js",

@@ -15,0 +15,0 @@ "types": "build/index.d.ts",

@@ -32,18 +32,16 @@ # AtomicAssets JavaScript

// contract: account name where the contract is deployed
// coreToken: Core token of the blockchain
// precision: Precision of the core token
// options:
// - fetch: either node-fetch module or the browser equivalent
// - rateLimit: defines how much requests per second can be made to not exceed the rate limit of the node
const api = new RpcApi("https://wax.pink.gg", "atomicassets", "WAX", 8, {fetch, rateLimit: 4});
const api = new RpcApi("https://testnet.wax.pink.gg", "atomicassets", {fetch, rateLimit: 4});
// fetch preset data
const preset = await api.getPreset("13456720837456");
const asset = await api.getAsset("leonleonleon", "1099511627786");
// create the action to mint an asset
const action = api.action.mintasset(
const actions = api.action.mintasset(
[{actor: "pinknetworkx", permission: "active"}],
"pinknetworkx", preset.id, "pinknetworkx", {"attr1": 10}, {"attr2": 20}
"collection", "scheme", -1, "pinknetworkx", {"name": "test"}, {"species": "test2"}
)
/* YOUR CODE HERE */
```

@@ -120,3 +118,3 @@

* gets a specific preset by id
* `async getScheme(name: string, cache: boolean = true): Promise<RpcScheme>`
* `async getScheme(collection: string, name: string, cache: boolean = true): Promise<RpcScheme>`
* get a scheme by its name

@@ -140,4 +138,6 @@ * `async getCollection(name: string, cache: boolean = true): Promise<RpcCollection>`

* `async preset(): Promise<RpcPreset>`
* `async backedTokens(): Promise<string>`
* `async collection(): Promise<RpcCollection>`
* `async scheme(): Promise<RpcScheme>`
* `async preset(): Promise<RpcPreset | null>`
* `async backedTokens(): Promise<string[]>`
* `async immutableData(): Promise<object>`

@@ -153,3 +153,2 @@ * `async mutableData(): Promise<object>`

* `async immutableData(): Promise<object>`
* `async mutableData(): Promise<object>`
* `async isTransferable(): Promise<boolean>`

@@ -162,3 +161,2 @@ * `async isBurnable(): Promise<boolean>`

##### RpcScheme
* `async author(): Promise<string>`
* `async format(): Promise<ISchema>`

@@ -169,4 +167,6 @@ * `async toObject(): Promise<object>`

* `async author(): Promise<string>`
* `async allowNotify(): Promise<boolean>`
* `async authorizedAccounts(): Promise<string[]>`
* `async notifyAccounts(): Promise<string[]>`
* `async marketFee(): Promise<number>`
* `async data(): Promise<any>`

@@ -178,4 +178,6 @@ * `async toObject(): Promise<object>`

* `async recipient(): Promise<string>`
* `async senderAssets(): Promise<RpcAsset[]>`
* `async recipientAssets(): Promise<RpcAsset[]>`
* `async senderAssets(): Promise<Array<RpcAsset | string>>`
* if element is a string, the asset is not owned by the sender anymore and the offer is invalid
* `async recipientAssets(): Promise<Array<RpcAsset | string>>`
* if element is a string, the asset is not owned by the recipient anymore and the offer is invalid
* `async memo(): Promise<string>`

@@ -182,0 +184,0 @@ * `async toObject(): Promise<object>`

@@ -14,3 +14,3 @@ export type EosioAuthorizationObject = {actor: string, permission: string};

export default class ActionGenerator {
constructor(public readonly contract: string, public readonly core_token: string, public readonly precision: number) { }
constructor(public readonly contract: string) { }

@@ -25,2 +25,6 @@ public async acceptoffer(authorization: EosioAuthorizationObject[], offer_id: string) {

public async addconftoken(authorization: EosioAuthorizationObject[], token_contract: string, token_symbol: string) {
return this._pack(authorization, "addconftoken", {token_contract, token_symbol});
}
public async addnotifyacc(authorization: EosioAuthorizationObject[], collection_name: string, account_to_add: string) {

@@ -30,2 +34,22 @@ return this._pack(authorization, "addnotifyacc", {collection_name, account_to_add});

public async admincoledit(authorization: EosioAuthorizationObject[], collection_format_extension: Format[]) {
return this._pack(authorization, "admincoledit", {collection_format_extension});
}
public async backsymbol(
authorization: EosioAuthorizationObject[], ram_payer: string, owner: string, asset_id: string, symbol_to_announce: string,
token_contract: string, quantity: string,
) {
const actions = this._pack(authorization, "backsymbol", {ram_payer, owner, asset_id, symbol_to_announce});
actions.push({
account: token_contract,
name: "transfer",
authorization,
data: {from: ram_payer, to: this.contract, quantity: quantity + " " + symbol_to_announce},
});
return actions;
}
public async burnasset(authorization: EosioAuthorizationObject[], owner: string, asset_id: string) {

@@ -40,6 +64,6 @@ return this._pack(authorization, "burnasset", {owner, asset_id});

public async createcol(
authorization: EosioAuthorizationObject[], author: string, collection_name: string,
authorized_accounts: string[], notify_accounts: string[], data: AttributeMap,
authorization: EosioAuthorizationObject[], author: string, collection_name: string, allow_notify: boolean,
authorized_accounts: string[], notify_accounts: string[], market_fee: number, data: AttributeMap,
) {
return this._pack(authorization, "createcol", {author, collection_name, authorized_accounts, notify_accounts, data});
return this._pack(authorization, "createcol", {author, collection_name, allow_notify, authorized_accounts, notify_accounts, market_fee, data});
}

@@ -54,13 +78,16 @@

public async createpre(
authorization: EosioAuthorizationObject[], authorized_creator: string, scheme_name: string, collection_name: string,
transferable: boolean, burnable: boolean, max_supply: string, immutable_data: AttributeMap, mutable_data: AttributeMap,
public async createpreset(
authorization: EosioAuthorizationObject[], authorized_creator: string, collection_name: string, scheme_name: string,
transferable: boolean, burnable: boolean, max_supply: string, immutable_data: AttributeMap,
) {
return this._pack(authorization, "createpre", {
authorized_creator, scheme_name, collection_name, transferable, burnable, max_supply, immutable_data, mutable_data,
return this._pack(authorization, "createpreset", {
authorized_creator, collection_name, scheme_name, transferable, burnable, max_supply, immutable_data,
});
}
public async createscheme(authorization: EosioAuthorizationObject[], author: string, scheme_name: string, scheme_format: Format[]) {
return this._pack(authorization, "createscheme", {scheme_name, scheme_format});
public async createscheme(
authorization: EosioAuthorizationObject[], authorized_creator: string,
collection_name: string, scheme_name: string, scheme_format: Format[],
) {
return this._pack(authorization, "createscheme", {authorized_creator, collection_name, scheme_name, scheme_format});
}

@@ -72,11 +99,18 @@

public async extendscheme(authorization: EosioAuthorizationObject[], scheme_name: string, scheme_format_extension: Format[]) {
return this._pack(authorization, "extendscheme", {scheme_name, scheme_format_extension});
public async extendscheme(
authorization: EosioAuthorizationObject[], authorized_editor: string,
collection_name: string, scheme_name: string, scheme_format_extension: Format[],
) {
return this._pack(authorization, "extendscheme", {authorized_editor, collection_name, scheme_name, scheme_format_extension});
}
public async forbidnotify(authorization: EosioAuthorizationObject[], collection_name: string) {
return this._pack(authorization, "forbidnotify", {collection_name});
}
public async mintasset(
authorization: EosioAuthorizationObject[], authorized_minter: string, preset_id: string,
authorization: EosioAuthorizationObject[], authorized_minter: string, collection_name: string, scheme_name: string, preset_id: string,
new_owner: string, immutable_data: AttributeMap, mutable_data: AttributeMap,
) {
return this._pack(authorization, "mintasset", {authorized_minter, preset_id, new_owner, immutable_data, mutable_data});
return this._pack(authorization, "mintasset", {authorized_minter, collection_name, scheme_name, preset_id, new_owner, immutable_data, mutable_data});
}

@@ -94,5 +128,5 @@

authorization: EosioAuthorizationObject[], authorized_editor: string,
owner: string, asset_id: string, mutable_data: AttributeMap,
owner: string, asset_id: string, new_mutable_data: AttributeMap,
) {
return this._pack(authorization, "setassetdata", {authorized_editor, owner, asset_id, mutable_data});
return this._pack(authorization, "setassetdata", {authorized_editor, owner, asset_id, new_mutable_data});
}

@@ -104,4 +138,4 @@

public async setpredata(authorization: EosioAuthorizationObject[], authorized_editor: string, preset_id: string, new_mutable_data: AttributeMap) {
return this._pack(authorization, "setpredata", {authorized_editor, preset_id, new_mutable_data});
public async setmarketfee(authorization: EosioAuthorizationObject[], collection_name: string, market_fee: number) {
return this._pack(authorization, "setmarketfee", {collection_name, market_fee});
}

@@ -113,14 +147,5 @@

public async backtokens(authorization: EosioAuthorizationObject[], owner: string, asset_id: string, payer: string, quantity: string) {
return {
account: "eosio.token",
name: "transfer",
authorization,
data: {from: payer, to: this.contract, quantity},
};
protected _pack(authorization: EosioAuthorizationObject[], name: string, data: any): EosioActionObject[] {
return [{ account: this.contract, name, authorization, data }];
}
protected _pack(authorization: EosioAuthorizationObject[], name: string, data: any): EosioActionObject {
return { account: this.contract, name, authorization, data };
}
}

@@ -30,3 +30,3 @@ import RpcApi from "../API/Rpc";

constructor(public readonly api: RpcApi) {
super(api.contract, api.coreToken, api.precision);
super(api.contract);
}

@@ -36,3 +36,3 @@

authorization: EosioAuthorizationObject[], author: string, collection_name: string,
authorized_accounts: string[], notify_accounts: string[], data: object,
allow_notify: boolean, authorized_accounts: string[], notify_accounts: string[], market_fee: number, data: object,
) {

@@ -42,18 +42,19 @@ const config = await this.api.config();

return super.createcol(
authorization, author, collection_name, authorized_accounts, notify_accounts, RpcActionGenerator.toAttributeMap(data, config.collection_format),
authorization, author, collection_name, allow_notify, authorized_accounts, notify_accounts, market_fee,
RpcActionGenerator.toAttributeMap(data, config.collection_format),
);
}
public async createpre(
authorization: EosioAuthorizationObject[], authorized_creator: string, scheme_name: string, collection_name: string,
transferable: boolean, burnable: boolean, max_supply: string, immutable_data: object, mutable_data: object,
public async createpreset(
authorization: EosioAuthorizationObject[], authorized_creator: string,
collection_name: string, scheme_name: string,
transferable: boolean, burnable: boolean, max_supply: string, immutable_data: object,
) {
const scheme = await this.api.getScheme(scheme_name);
const scheme = await this.api.getScheme(collection_name, scheme_name);
const idata = RpcActionGenerator.toAttributeMap(immutable_data, await scheme.rawFormat());
const mdata = RpcActionGenerator.toAttributeMap(mutable_data, await scheme.rawFormat());
const immutable_attribute_map = RpcActionGenerator.toAttributeMap(immutable_data, await scheme.rawFormat());
return super.createpre(
authorization, authorized_creator, scheme_name, collection_name,
transferable, burnable, max_supply, idata, mdata,
return super.createpreset(
authorization, authorized_creator, collection_name, scheme_name,
transferable, burnable, max_supply, immutable_attribute_map,
);

@@ -63,3 +64,4 @@ }

public async mintasset(
authorization: EosioAuthorizationObject[], authorized_minter: string, preset_id: string,
authorization: EosioAuthorizationObject[], authorized_minter: string,
collection_name: string, scheme_name: string, preset_id: string,
new_owner: string, immutable_data: object, mutable_data: object,

@@ -69,6 +71,9 @@ ) {

const idata = RpcActionGenerator.toAttributeMap(immutable_data, await (await preset.scheme()).rawFormat());
const mdata = RpcActionGenerator.toAttributeMap(mutable_data, await (await preset.scheme()).rawFormat());
const immutable_attribute_map = RpcActionGenerator.toAttributeMap(immutable_data, await (await preset.scheme()).rawFormat());
const mutable_attribute_map = RpcActionGenerator.toAttributeMap(mutable_data, await (await preset.scheme()).rawFormat());
return super.mintasset(authorization, authorized_minter, preset_id, new_owner, idata, mdata);
return super.mintasset(
authorization, authorized_minter, collection_name, scheme_name, preset_id,
new_owner, immutable_attribute_map, mutable_attribute_map,
);
}

@@ -80,7 +85,7 @@

const asset = await this.api.getAsset(owner, asset_id);
const scheme = await (await asset.preset()).scheme();
const scheme = await asset.scheme();
const mdata = RpcActionGenerator.toAttributeMap(mutable_data, await scheme.rawFormat());
const mutable_attribute_map = RpcActionGenerator.toAttributeMap(mutable_data, await scheme.rawFormat());
return super.setassetdata(authorization, authorized_editor, owner, asset_id, mdata);
return super.setassetdata(authorization, authorized_editor, owner, asset_id, mutable_attribute_map);
}

@@ -93,10 +98,2 @@

}
public async setpredata(authorization: EosioAuthorizationObject[], authorized_editor: string, preset_id: string, new_mutable_data: AttributeMap) {
const preset = await this.api.getPreset(preset_id);
const mdata = RpcActionGenerator.toAttributeMap(new_mutable_data, await (await preset.scheme()).rawFormat());
return super.setpredata(authorization, authorized_editor, preset_id, mdata);
}
}
import bigInt from "big-integer";
import {deserialize} from "../../Serialization";
import {AssetRow} from "./Cache";
import {IAssetRow} from "./Cache";
import RpcCollection from "./Collection";
import RpcApi from "./index";
import RpcPreset from "./Preset";
import RpcScheme from "./Scheme";

@@ -11,7 +13,20 @@ export default class RpcAsset {

// tslint:disable-next-line:variable-name
private readonly _data: Promise<AssetRow>;
private readonly _data: Promise<IAssetRow>;
// tslint:disable-next-line:variable-name
private readonly _preset: Promise<RpcPreset>;
private readonly _preset: Promise<RpcPreset | null>;
// tslint:disable-next-line:variable-name
private readonly _collection: Promise<RpcCollection>;
// tslint:disable-next-line:variable-name
private readonly _scheme: Promise<RpcScheme>;
public constructor(private readonly api: RpcApi, owner: string, id: string, data?: AssetRow, preset?: RpcPreset, cache: boolean = true) {
public constructor(
private readonly api: RpcApi,
owner: string,
id: string,
data?: IAssetRow,
collection?: RpcCollection,
scheme?: RpcScheme,
preset?: RpcPreset,
cache: boolean = true,
) {
this.id = id;

@@ -38,2 +53,6 @@

if(Number(row.preset_id) < 0) {
return resolve(null);
}
resolve(new RpcPreset(api, row.preset_id, undefined, undefined, undefined, cache));

@@ -45,30 +64,60 @@ } catch (e) {

});
this._collection = new Promise(async (resolve, reject) => {
if(collection) {
resolve(collection);
} else {
try {
const row = await this._data;
resolve(new RpcCollection(api, row.collection_name, undefined, cache));
} catch (e) {
reject(e);
}
}
});
this._scheme = new Promise(async (resolve, reject) => {
if(scheme) {
resolve(scheme);
} else {
try {
const row = await this._data;
resolve(new RpcScheme(api, row.collection_name, row.scheme_name, undefined, cache));
} catch (e) {
reject(e);
}
}
});
}
public async preset(): Promise<RpcPreset> {
public async preset(): Promise<RpcPreset | null> {
return await this._preset;
}
public async backedTokens(): Promise<string> {
return bigInt((await this._data).backed_core_amount).divide(this.api.precision).toString();
public async collection(): Promise<RpcCollection> {
return await this._collection;
}
public async immutableData(): Promise<object | string> {
const preset = await this.preset();
const scheme = await preset.scheme();
public async scheme(): Promise<RpcScheme> {
return await this._scheme;
}
const data = await this._data;
const pdata = await preset.immutableData();
public async backedTokens(): Promise<string[]> {
return (await this._data).backed_tokens;
}
return Object.assign({}, pdata, deserialize(data.immutable_serialized_data, await scheme.format()));
public async immutableData(): Promise<object> {
const scheme = await this.scheme();
const row = await this._data;
return deserialize(row.immutable_serialized_data, await scheme.format());
}
public async mutableData(): Promise<object | string> {
const preset = await this.preset();
const scheme = await preset.scheme();
public async mutableData(): Promise<object> {
const scheme = await this.scheme();
const row = await this._data;
const data = await this._data;
const pdata = await preset.mutableData();
return Object.assign({}, pdata, deserialize(data.mutable_serialized_data, await scheme.format()));
return deserialize(row.mutable_serialized_data, await scheme.format());
}

@@ -80,14 +129,26 @@

return Object.assign({}, mutableData, immutableData);
const preset = await this.preset();
const presetData = preset ? await preset.immutableData() : {};
return Object.assign({}, mutableData, immutableData, presetData);
}
public async toObject(): Promise<object> {
const preset = await this.preset();
const collection = await this.collection();
const scheme = await this.scheme();
return {
id: this.id,
asset_id: this.id,
collection: await collection.toObject(),
scheme: await scheme.toObject(),
preset: preset ? await preset.toObject() : null,
backedTokens: await this.backedTokens(),
immutableData: await this.immutableData(),
mutableData: await this.mutableData(),
preset: await (await this.preset()).toObject(),
data: await this.data(),
};
}
}

@@ -1,65 +0,57 @@

import {byte_vector_to_int} from "../../Serialization/Binary";
export type SchemeFormat = Array<{name: string, type: string}>;
export type AssetRow = {
id: string, preset_id: string, ram_payer: string, backed_core_amount: string,
immutable_serialized_data: Uint8Array, mutable_serialized_data: Uint8Array,
};
export type PresetRow = {
scheme_name: string, collection_name: string,
transferable: boolean, burnable: boolean,
max_supply: number, issued_supply: number,
mutable_serialized_data: Uint8Array,
immutable_serialized_data: Uint8Array,
};
export type SchemeRow = {scheme_name: string, author: string, format: SchemeFormat};
export type CollectionRow = {collection_name: string, author: string, authorized_accounts: string[], notify_accounts: string[], serialized_data: Uint8Array};
export type OfferRow = {
id: string, offer_sender: string, offer_recipient: string,
sender_asset_ids: string[], recipient_asset_ids: string[],
memo: string,
};
export type ConfigRow = {offer_counter: string, collection_format: SchemeFormat};
export interface ICollectionRow {
collection_name: string;
author: string;
allow_notify: boolean;
authorized_accounts: string[];
notify_accounts: string[];
market_fee: number;
serialized_data: Uint8Array;
}
export default class RpcCache {
private readonly assets: {[id: string]: {data: AssetRow, expiration: number, updated: number}} = {};
private readonly presets: {[id: string]: {data: PresetRow, expiration: number, updated: number}} = {};
private readonly schemes: {[id: string]: {data: SchemeRow, expiration: number, updated: number}} = {};
private readonly collections: {[id: string]: {data: CollectionRow, expiration: number, updated: number}} = {};
private readonly offers: {[id: string]: {data: OfferRow, expiration: number, updated: number}} = {};
export interface ISchemeRow {
scheme_name: string;
format: SchemeFormat;
}
public asset(assetID: string, data?: any | null | false): AssetRow | undefined {
if(data) {
data.mutable_serialized_data = new Uint8Array(data.mutable_serialized_data);
data.immutable_serialized_data = new Uint8Array(data.immutable_serialized_data);
}
export interface IPresetRow {
preset_id: number;
collection_name: string;
scheme_name: string;
transferable: boolean;
burnable: boolean;
max_supply: number;
issued_supply: number;
immutable_serialized_data: Uint8Array;
}
return this.access<AssetRow>(assetID, this.assets, data);
}
export interface IAssetRow {
asset_id: string;
collection_name: string;
scheme_name: string;
preset_id: string;
ram_payer: string;
backed_tokens: string[];
immutable_serialized_data: Uint8Array;
mutable_serialized_data: Uint8Array;
}
public preset(presetID: string, data?: any | null | false): PresetRow | undefined {
if(data) {
data.mutable_serialized_data = new Uint8Array(data.mutable_serialized_data);
data.immutable_serialized_data = new Uint8Array(data.immutable_serialized_data);
data.max_supply = byte_vector_to_int(new Uint8Array(data.max_supply));
data.issued_supply = byte_vector_to_int(new Uint8Array(data.issued_supply));
}
export interface IOfferRow {
offer_id: string;
offer_sender: string;
offer_recipient: string;
sender_asset_ids: string[];
recipient_asset_ids: string[];
memo: string;
}
return this.access<PresetRow>(presetID, this.presets, data);
}
export interface IConfigRow {
asset_counter: string;
offer_counter: string;
collection_format: SchemeFormat;
}
public scheme(scheme: string, data?: any | null | false): SchemeRow | undefined {
return this.access<SchemeRow>(scheme, this.schemes, data);
}
public collection(collection: string, data?: any | null | false): CollectionRow | undefined {
return this.access<CollectionRow>(collection, this.collections, data);
}
public offer(offerID: string, data?: any | null | false): OfferRow | undefined {
return this.access<OfferRow>(offerID, this.offers, data);
}
private access<T>(
export default class RpcCache {
private static access<T>(
identifier: string | number,

@@ -92,2 +84,37 @@ cache: {[id: string]: {expiration: number, updated: number, data: T}},

}
private readonly assets: {[id: string]: {data: IAssetRow, expiration: number, updated: number}} = {};
private readonly presets: {[id: string]: {data: IPresetRow, expiration: number, updated: number}} = {};
private readonly schemes: {[id: string]: {data: ISchemeRow, expiration: number, updated: number}} = {};
private readonly collections: {[id: string]: {data: ICollectionRow, expiration: number, updated: number}} = {};
private readonly offers: {[id: string]: {data: IOfferRow, expiration: number, updated: number}} = {};
public asset(assetID: string, data?: any | null | false): IAssetRow | undefined {
if(data) {
data.mutable_serialized_data = new Uint8Array(data.mutable_serialized_data);
data.immutable_serialized_data = new Uint8Array(data.immutable_serialized_data);
}
return RpcCache.access<IAssetRow>(assetID, this.assets, data);
}
public preset(presetID: string, data?: any | null | false): IPresetRow | undefined {
if(data) {
data.immutable_serialized_data = new Uint8Array(data.immutable_serialized_data);
}
return RpcCache.access<IPresetRow>(presetID, this.presets, data);
}
public scheme(scheme: string, data?: any | null | false): ISchemeRow | undefined {
return RpcCache.access<ISchemeRow>(scheme, this.schemes, data);
}
public collection(collection: string, data?: any | null | false): ICollectionRow | undefined {
return RpcCache.access<ICollectionRow>(collection, this.collections, data);
}
public offer(offerID: string, data?: any | null | false): IOfferRow | undefined {
return RpcCache.access<IOfferRow>(offerID, this.offers, data);
}
}
import {ObjectSchema} from "../../Schema";
import {deserialize} from "../../Serialization";
import {CollectionRow} from "./Cache";
import {ICollectionRow} from "./Cache";
import RpcApi from "./index";

@@ -10,5 +10,5 @@

// tslint:disable-next-line:variable-name
private readonly _data: Promise<CollectionRow>;
private readonly _data: Promise<ICollectionRow>;
public constructor(private readonly api: RpcApi, name: string, data?: CollectionRow, cache: boolean = true) {
public constructor(private readonly api: RpcApi, name: string, data?: ICollectionRow, cache: boolean = true) {
this.name = name;

@@ -33,2 +33,6 @@

public async allowNotify(): Promise<boolean> {
return !!(await this._data).allow_notify;
}
public async authorizedAccounts(): Promise<string[]> {

@@ -42,2 +46,6 @@ return (await this._data).authorized_accounts;

public async marketFee(): Promise<number> {
return Number((await this._data).market_fee);
}
public async data(): Promise<any> {

@@ -49,5 +57,10 @@ return deserialize((await this._data).serialized_data, ObjectSchema((await this.api.config()).collection_format));

return {
collection_name: this.name,
author: await this.author(),
allowNotify: await this.allowNotify(),
authorizedAccounts: await this.authorizedAccounts(),
notifyAccounts: await this.notifyAccounts(),
marketFee: await this.marketFee(),
data: await this.data(),

@@ -54,0 +67,0 @@ };

@@ -5,3 +5,3 @@ import ActionGenerator from "../../Actions/Generator";

import RpcAsset from "./Asset";
import RpcCache, {ConfigRow} from "./Cache";
import RpcCache, {IConfigRow} from "./Cache";
import RpcCollection from "./Collection";

@@ -23,4 +23,2 @@ import RpcOffer from "./Offer";

public readonly contract: string;
public readonly coreToken: string;
public readonly precision: number;

@@ -30,9 +28,7 @@ private readonly fetchBuiltin: Fetch;

// tslint:disable-next-line:variable-name
private readonly _config: Promise<ConfigRow>;
private readonly _config: Promise<IConfigRow>;
constructor(endpoint: string, contract: string, coreToken: string, precision: number, args: ApiArgs = {rateLimit: 4}) {
constructor(endpoint: string, contract: string, args: ApiArgs = {rateLimit: 4}) {
this.endpoint = endpoint;
this.contract = contract;
this.coreToken = coreToken;
this.precision = precision;

@@ -66,3 +62,3 @@ if (args.fetch) {

public async config(): Promise<ConfigRow> {
public async config(): Promise<IConfigRow> {
return await this._config;

@@ -76,3 +72,3 @@ }

return new RpcAsset(this, owner, id, undefined, undefined, cache);
return new RpcAsset(this, owner, id, undefined, undefined, undefined, undefined, cache);
}

@@ -96,3 +92,3 @@

public async getScheme(name: string, cache: boolean = true): Promise<RpcScheme> {
public async getScheme(collection: string, name: string, cache: boolean = true): Promise<RpcScheme> {
if(!cache) {

@@ -102,3 +98,3 @@ this.cache.scheme(name, null);

return new RpcScheme(this, name, undefined, cache);
return new RpcScheme(this, collection, name, undefined, cache);
}

@@ -115,4 +111,4 @@

public async getAccountOffers(account: string, cache: boolean = true): Promise<RpcOffer[]> {
return (await this.queue.account_offers(account)).map((offer) => {
return new RpcOffer(this, offer.id, offer, undefined, undefined, cache);
return (await this.queue.account_offers(account)).map((offerRow) => {
return new RpcOffer(this, offerRow.offer_id, offerRow, undefined, undefined, cache);
});

@@ -122,4 +118,4 @@ }

public async getAccountAssets(account: string, cache: boolean = true): Promise<RpcAsset[]> {
return (await this.queue.account_assets(account)).map((asset) => {
return new RpcAsset(this, account, asset.id, asset, undefined, cache);
return (await this.queue.account_assets(account)).map((assetRow) => {
return new RpcAsset(this, account, assetRow.asset_id, assetRow, undefined, undefined, undefined, cache);
});

@@ -126,0 +122,0 @@ }

import RpcAsset from "./Asset";
import {AssetRow, OfferRow} from "./Cache";
import {IAssetRow, IOfferRow} from "./Cache";
import RpcApi from "./index";

@@ -9,9 +9,9 @@

// tslint:disable-next-line:variable-name
private readonly _data: Promise<OfferRow>;
private readonly _data: Promise<IOfferRow>;
// tslint:disable-next-line:variable-name
private readonly _senderAssets: Promise<RpcAsset[]>;
private readonly _senderAssets: Promise<Array<string | RpcAsset>>;
// tslint:disable-next-line:variable-name
private readonly _recipientAssets: Promise<RpcAsset[]>;
private readonly _recipientAssets: Promise<Array<string | RpcAsset>>;
constructor(private readonly api: RpcApi, id: string, data?: OfferRow, senderAssets?: RpcAsset[], receiverAssets?: RpcAsset[], cache: boolean = true) {
constructor(private readonly api: RpcApi, id: string, data?: IOfferRow, senderAssets?: RpcAsset[], receiverAssets?: RpcAsset[], cache: boolean = true) {
this.id = id;

@@ -36,14 +36,10 @@

try {
const row: OfferRow = await this._data;
const inventory: AssetRow[] = await this.api.queue.account_assets(row.offer_sender, cache);
const row: IOfferRow = await this._data;
const inventory: IAssetRow[] = await this.api.queue.account_assets(row.offer_sender, cache);
const offerAssets = inventory.filter((element) => {
return row.sender_asset_ids.indexOf(element.id) >= 0;
});
return resolve(row.sender_asset_ids.map((assetID) => {
const asset = inventory.find((assetRow) => assetRow.asset_id === assetID);
if(offerAssets.length !== row.sender_asset_ids.length) {
return reject(new Error("user does not own all items anymore"));
}
return resolve(offerAssets.map((asset) => new RpcAsset(this.api, row.offer_sender, asset.id, asset)));
return asset ? new RpcAsset(this.api, row.offer_sender, assetID, asset, undefined, undefined, undefined, cache) : assetID;
}));
} catch (e) {

@@ -60,14 +56,10 @@ return reject(e);

try {
const row: OfferRow = await this._data;
const row: IOfferRow = await this._data;
const inventory: IAssetRow[] = await this.api.queue.account_assets(row.offer_recipient, cache);
const inventory: AssetRow[] = await this.api.queue.account_assets(row.offer_recipient, cache);
const offerAssets = inventory.filter((element) => {
return row.recipient_asset_ids.indexOf(element.id) >= 0;
});
return resolve(row.recipient_asset_ids.map((assetID) => {
const asset = inventory.find((assetRow) => assetRow.asset_id === assetID);
if(offerAssets.length !== row.recipient_asset_ids.length) {
return reject(new Error("user does not own all items anymore"));
}
return resolve(offerAssets.map((asset) => new RpcAsset(this.api, row.offer_recipient, asset.id, asset)));
return asset ? new RpcAsset(this.api, row.offer_recipient, assetID, asset, undefined, undefined, undefined, cache) : assetID;
}));
} catch (e) {

@@ -88,7 +80,7 @@ return reject(e);

public async senderAssets(): Promise<RpcAsset[]> {
public async senderAssets(): Promise<Array<RpcAsset | string>> {
return await this._senderAssets;
}
public async recipientAssets(): Promise<RpcAsset[]> {
public async recipientAssets(): Promise<Array<RpcAsset | string>> {
return await this._recipientAssets;

@@ -103,10 +95,10 @@ }

return {
id: this.id,
offer_id: this.id,
sender: {
account: await this.sender(),
assets: await Promise.all((await this.senderAssets()).map(async (asset) => await asset.toObject())),
assets: await Promise.all((await this.senderAssets()).map(async (asset) => typeof asset === "string" ? asset : await asset.toObject())),
},
recipient: {
account: await this.recipient(),
assets: await Promise.all((await this.recipientAssets()).map(async (asset) => await asset.toObject())),
assets: await Promise.all((await this.recipientAssets()).map(async (asset) => typeof asset === "string" ? asset : await asset.toObject())),
},

@@ -113,0 +105,0 @@ memo: await this.memo(),

import {deserialize} from "../../Serialization";
import {hex_encode} from "../../Serialization/Binary";
import {PresetRow} from "./Cache";
import {IPresetRow} from "./Cache";
import RpcCollection from "./Collection";

@@ -12,3 +12,3 @@ import RpcApi from "./index";

// tslint:disable-next-line:variable-name
private readonly _data: Promise<PresetRow>;
private readonly _data: Promise<IPresetRow>;

@@ -20,3 +20,3 @@ // tslint:disable-next-line:variable-name

public constructor(private readonly api: RpcApi, id: string, data?: PresetRow, scheme?: RpcScheme, collection?: RpcCollection, cache: boolean = true) {
public constructor(private readonly api: RpcApi, id: string, data?: IPresetRow, scheme?: RpcScheme, collection?: RpcCollection, cache: boolean = true) {
this.id = id;

@@ -43,3 +43,3 @@

resolve(new RpcScheme(this.api, row.scheme_name, undefined, cache));
resolve(new RpcScheme(this.api, row.collection_name, row.scheme_name, undefined, cache));
} catch (e) {

@@ -80,8 +80,2 @@ reject(e);

public async mutableData(): Promise<object> {
const scheme = await this._scheme;
return deserialize((await this._data).mutable_serialized_data, await scheme.format());
}
public async isTransferable(): Promise<boolean> {

@@ -105,7 +99,7 @@ return !!(await this._data).transferable;

return {
id: this.id,
preset_id: this.id,
collection: await (await this.collection()).toObject(),
scheme: await (await this.scheme()).toObject(),
immutableData: await this.immutableData(),
mutableData: await this.mutableData(),
transferable: await this.isTransferable(),

@@ -112,0 +106,0 @@ burnable: await this.isBurnable(),

import RpcError from "../../Errors/RpcError";
import {AssetRow, CollectionRow, OfferRow, PresetRow, SchemeRow} from "./Cache";
import {IAssetRow, ICollectionRow, IOfferRow, IPresetRow, ISchemeRow} from "./Cache";
import RpcApi from "./index";

@@ -12,27 +12,27 @@ import RpcOffer from "./Offer";

public async asset(owner: string, id: string, useCache: boolean = true): Promise<AssetRow> {
public async asset(owner: string, id: string, useCache: boolean = true): Promise<IAssetRow> {
return this.fetch_single_row(owner, "assets", id, this.api.cache.asset.bind(this.api.cache), useCache);
}
public async account_assets(account: string, useCache: boolean = true): Promise<AssetRow[]> {
public async account_assets(account: string, useCache: boolean = true): Promise<IAssetRow[]> {
return this.fetch_all_rows(account, "assets", "id", "", "", this.api.cache.asset.bind(this.api.cache), useCache);
}
public async preset(id: string, useCache: boolean = true): Promise<PresetRow> {
public async preset(id: string, useCache: boolean = true): Promise<IPresetRow> {
return this.fetch_single_row(this.api.contract, "presets", id, this.api.cache.preset.bind(this.api.cache), useCache);
}
public async scheme(name: string, useCache: boolean = true): Promise<SchemeRow> {
return this.fetch_single_row(this.api.contract, "schemes", name, this.api.cache.scheme.bind(this.api.cache), useCache);
public async scheme(collection: string, name: string, useCache: boolean = true): Promise<ISchemeRow> {
return this.fetch_single_row(collection, "schemes", name, this.api.cache.scheme.bind(this.api.cache), useCache);
}
public async collection(name: string, useCache: boolean = true): Promise<CollectionRow> {
public async collection(name: string, useCache: boolean = true): Promise<ICollectionRow> {
return this.fetch_single_row(this.api.contract, "collections", name, this.api.cache.collection.bind(this.api.cache), useCache);
}
public async offer(id: string, useCache: boolean = true): Promise<OfferRow> {
public async offer(id: string, useCache: boolean = true): Promise<IOfferRow> {
return this.fetch_single_row(this.api.contract, "offers", id, this.api.cache.offer.bind(this.api.cache), useCache);
}
public async account_offers(account: string, useCache: boolean = true): Promise<OfferRow[]> {
public async account_offers(account: string, useCache: boolean = true): Promise<IOfferRow[]> {
const rows: any[][] = await Promise.all([

@@ -39,0 +39,0 @@ this.fetch_all_rows(

import {ISchema, ObjectSchema} from "../../Schema";
import {SchemeRow} from "./Cache";
import {ISchemeRow} from "./Cache";
import RpcApi from "./index";

@@ -9,5 +9,5 @@

// tslint:disable-next-line:variable-name
private readonly _data: Promise<SchemeRow>;
private readonly _data: Promise<ISchemeRow>;
public constructor(private readonly api: RpcApi, name: string, data?: SchemeRow, cache: boolean = true) {
public constructor(private readonly api: RpcApi, collection: string, name: string, data?: ISchemeRow, cache: boolean = true) {
this.name = name;

@@ -20,3 +20,3 @@

try {
resolve(await api.queue.scheme(name, cache));
resolve(await api.queue.scheme(collection, name, cache));
} catch (e) {

@@ -29,6 +29,2 @@ reject(e);

public async author(): Promise<string> {
return (await this._data).author;
}
public async format(): Promise<ISchema> {

@@ -44,3 +40,3 @@ return ObjectSchema((await this._data).format);

return {
author: await this.author(),
scheme_name: this.name,
format: (await this._data).format,

@@ -47,0 +43,0 @@ };

@@ -5,3 +5,4 @@ import ExplorerApi from "./API/Explorer";

import {deserialize, serialize} from "./Serialization";
import {ParserTypes} from "./Serialization/Types";
export {RpcApi, ExplorerApi, ObjectSchema, deserialize, serialize};
export {RpcApi, ExplorerApi, ObjectSchema, deserialize, serialize, ParserTypes};
import { expect } from "chai";
import RpcApi from "../src/API/Rpc";
import RpcAsset from "../src/API/Rpc/Asset";

@@ -8,3 +9,3 @@ // tslint:disable-next-line:no-var-requires

describe("RPC API", () => {
const api = new RpcApi("https://testnet.wax.pink.gg", "atomicassets", "WAX", 8, {
const api = new RpcApi("https://testnet.wax.pink.gg", "atomicassets", {
fetch, rateLimit: 4,

@@ -15,3 +16,3 @@ });

owner: "leonleonleon",
id: "1099511627780",
id: "1099511627786",
};

@@ -42,2 +43,10 @@

}).timeout(20000);
it("fetch assets ", async () => {
const assets = await api.getAccountAssets(exampleAsset.owner);
const result = await Promise.all(assets.map(async (asset) => await asset.toObject()));
expect(result).to.deep.equal(result);
}).timeout(20000);
});

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc