@newcoin-foundation/newcoin-sdk
Version:
SDK for Newcoin blockchain
251 lines (248 loc) • 9.45 kB
JavaScript
var ActionGenerator = /** @class */ (function () {
function ActionGenerator(contract, token_contract) {
this.contract = contract;
this.token_contract = token_contract;
this.newaccount = function (new_name, payer, newacc_public_active_key, newacc_public_owner_key) { return ({
account: 'eosio',
name: 'newaccount',
authorization: [{
actor: payer,
permission: 'active',
}],
data: {
creator: payer,
name: new_name,
owner: {
threshold: 1,
keys: [{
key: newacc_public_owner_key,
weight: 1
}],
accounts: [],
waits: []
},
active: {
threshold: 1,
keys: [{
key: newacc_public_active_key,
weight: 1
}],
accounts: [],
waits: []
},
}
}); };
this.buyrambytes = function (receiver, payer, amt) {
if (payer === void 0) { payer = 'io'; }
if (amt === void 0) { amt = 8192; }
return ({
account: 'eosio',
name: 'buyrambytes',
authorization: [{ actor: payer, permission: 'active' }],
data: {
payer: payer,
receiver: receiver,
bytes: amt,
},
});
};
this.delegateBw = function (receiver, payer, net_amount, cpu_amount, trfer) {
if (payer === void 0) { payer = 'io'; }
if (net_amount === void 0) { net_amount = '100.0000 NCO'; }
if (cpu_amount === void 0) { cpu_amount = '100.0000 NCO'; }
if (trfer === void 0) { trfer = true; }
return ({
account: 'eosio',
name: 'delegatebw',
authorization: [{
actor: payer,
permission: 'active',
}],
data: {
from: payer,
receiver: receiver,
stake_net_quantity: net_amount,
stake_cpu_quantity: cpu_amount,
transfer: trfer,
}
});
};
/*createUser = async (
newUser: string,
payer: string,
public_active_key: string,
public_owner_key: string
) => {
let newacc_action = this._newaccount(newUser, payer, public_active_key, public_owner_key);
let buyram_action = this._buyrambytes(newUser, payer);
let delegatebw_action = this._delegateBw(newUser, payer);
return [newacc_action, buyram_action, delegatebw_action]
};
createAccount(
authorization: EosioAuthorizationObject[],
owner: string,
symbol: string,
payer: string
) {
return this._pack(this.contract, authorization, "open", {
owner,
symbol,
payer
});
}*/
this.createCollection = function (author, collection_name, authorized_accounts, notify_accounts, market_fee, allow_notify) {
if (notify_accounts === void 0) { notify_accounts = []; }
var action = {
account: 'atomicassets',
name: 'createcol',
data: {
author: author,
collection_name: collection_name,
allow_notify: allow_notify,
authorized_accounts: authorized_accounts,
notify_accounts: notify_accounts,
market_fee: market_fee,
data: []
},
authorization: [
{ actor: author, permission: 'active' }
]
};
return action;
};
this.createSchema = function (author, collection_name, schema_name, sch) {
var action = {
account: 'atomicassets',
name: 'createschema',
data: {
authorized_creator: author,
collection_name: collection_name,
schema_name: schema_name,
schema_format: sch
},
authorization: [
{ actor: author, permission: 'active' }
]
};
return action;
};
this.createTemplate = function (author, collection_name, schema_name, xferable, burnable, template_fields) {
var action = {
account: 'atomicassets',
name: 'createtempl',
data: {
authorized_creator: author,
collection_name: collection_name,
schema_name: schema_name,
transferable: xferable,
burnable: burnable,
max_supply: 0xffffff,
immutable_data: template_fields //{key: 'name', value: ['string', 'default'] } ]
},
authorization: [
{ actor: author, permission: 'active' }
]
};
return action;
};
this.createPermission = function (author, perm_name, perm_key) {
var authorization_object = {
threshold: 1,
accounts: [{ permission: { actor: author, permission: 'active' }, weight: 1 }],
keys: [{ key: perm_key, weight: 1 }],
waits: []
};
var updateauth_input = {
account: author,
permission: perm_name,
parent: 'active',
auth: authorization_object
};
var action = {
account: 'eosio',
name: 'updateauth',
data: updateauth_input,
authorization: [
{ actor: author, permission: 'active' }
]
};
return action;
};
this.mintAsset = function (author, col_name, sch_name, tmpl_id, immutable_data, mutable_data) {
var action = {
account: 'atomicassets',
name: 'mintasset',
data: {
authorized_minter: author,
collection_name: col_name,
schema_name: sch_name,
template_id: tmpl_id,
new_asset_owner: author,
immutable_data: immutable_data,
mutable_data: mutable_data,
tokens_to_back: [] //tokens to back
},
authorization: [
{ actor: author, permission: 'active' }
]
};
return action;
};
this.createPool = function (creator, ticker, is_inflatable, is_deflatable, is_treasury, descr) {
var action = {
account: 'pools2.nco',
name: 'createpool',
data: {
owner: creator,
ticker: ticker,
description: descr,
is_inflatable: is_inflatable,
is_deflatable: is_deflatable,
is_treasury: is_treasury
},
authorization: [
{ actor: creator, permission: 'active' }
]
};
return action;
};
this.txNcoBalance = function (from, to, amt, memo) {
var action = {
account: 'eosio.token',
name: 'transfer',
data: {
from: from,
to: to,
quantity: amt,
memo: memo //''
},
authorization: [
{ 'actor': from, 'permission': 'active' }
]
};
return action;
};
this.txBalance = function (contract, from, to, amt, memo) {
var action = {
account: contract,
name: 'transfer',
data: {
from: from,
to: to,
quantity: amt,
memo: memo //''
},
authorization: [
{ 'actor': from, 'permission': 'active' }
]
};
return action;
};
}
ActionGenerator.prototype._pack = function (account, authorization, name, data) {
return [{ account: account, name: name, authorization: authorization, data: data }];
};
return ActionGenerator;
}());
export { ActionGenerator };
//# sourceMappingURL=actions.js.map