UNPKG

@open-rights-exchange/orejs

Version:

Orejs is a Javascript helper library to provide simple high-level access to the ore-protocol. Orejs uses eosJS as a wrapper to the EOS blockchain.

101 lines 7.81 kB
"use strict"; /* Public */ var _a = require('./compose'), ChainAction = _a.ChainAction, composeAction = _a.composeAction; // Initializes createbridge with the following details: // Only the createbridge account can call this action // symbol = the core token of the chain or the token used to pay for new user accounts of the chain // precision = precision of the core token of the chain // newAccountContract = the contract to call for new account action // minimumRAM = minimum bytes of RAM to put in a new account created on the chain function init(symbol, precision, newAccountContract, newAccountAction, minimumRAM, options) { var _a = options.contractName, contractName = _a === void 0 ? 'createbridge' : _a, _b = options.permission, permission = _b === void 0 ? 'active' : _b, _c = options.broadcast, broadcast = _c === void 0 ? true : _c; var chainSymbol = precision + "," + symbol; var args = { contractName: contractName, chainSymbol: chainSymbol, newAccountContract: newAccountContract, newAccountAction: newAccountAction, minimumRAM: minimumRAM, permission: permission }; var action = composeAction(ChainAction.CreateBridge_init, args); var actions = [action]; return this.transact(actions, broadcast); } // Registers an app with the createbridge contract. Called with the following parameter: // authorizingAccount = an object with account name and permission to be registered as the owner of the app // appName: = the string/account name representing the app // ram: = bytes of ram to put in the new user account created for the app (defaults to 4kb) // net = amount to be staked for net // cpu = amount to be staked for cpu // airdropContract = name of the airdrop contract // airdropToken = total number of tokens to be airdropped // airdroplimit = number of tokens to be airdropped to the newly created account function define(authorizingAccount, appName, ram, net, cpu, pricekey, options) { if (ram === void 0) { ram = 4096; } var airdropContract = options.airdropContract, airdropToken = options.airdropToken, airdropLimit = options.airdropLimit, _a = options.contractName, contractName = _a === void 0 ? 'createbridge' : _a, _b = options.broadcast, broadcast = _b === void 0 ? true : _b; var accountName = authorizingAccount.accountName, _c = authorizingAccount.permission, permission = _c === void 0 ? 'active' : _c; var airdrop = { contract: airdropContract, tokens: airdropToken, limit: airdropLimit }; var args = { accountName: accountName, airdrop: airdrop, appName: appName, contractName: contractName, cpu: cpu, permission: permission, net: net, pricekey: pricekey, ram: ram }; var action = composeAction(ChainAction.CreateBridge_Define, args); var actions = [action]; return this.transact(actions, broadcast); } // Creates a new user account. It also airdrops custom dapp tokens to the new user account if an app owner has opted for airdrops // authorizingAccount = an object with account name and permission of the account paying for the balance left after getting the donation from the app contributors // keys = owner key and active key for the new account // origin = the string representing the app to create the new user account for. For ex- everipedia.org, lumeos function createNewAccount(authorizingAccount, keys, options) { var accountName = authorizingAccount.accountName, permission = authorizingAccount.permission; var origin = options.origin, oreAccountName = options.oreAccountName, _a = options.contractName, contractName = _a === void 0 ? 'createbridge' : _a, _b = options.broadcast, broadcast = _b === void 0 ? true : _b, _c = options.referral, referral = _c === void 0 ? '' : _c; var _d = keys.publicKeys, activekey = _d.active, ownerkey = _d.owner; var args = { accountName: accountName, activekey: activekey, contractName: contractName, oreAccountName: oreAccountName, origin: origin, ownerkey: ownerkey, permission: permission, referral: referral }; var action = composeAction(ChainAction.CreateBridge_Create, args); var actions = [action]; return this.transact(actions, broadcast); } // Owner account of an app can whitelist other accounts. // authorizingAccount = an object with account name and permission contributing towards an app // whitelistAccount = account name to be whitelisted to create accounts on behalf of the app function whitelist(authorizingAccount, whitelistAccount, appName, options) { var _a = options.contractName, contractName = _a === void 0 ? 'createbridge' : _a, _b = options.broadcast, broadcast = _b === void 0 ? true : _b; var accountName = authorizingAccount.accountName, _c = authorizingAccount.permission, permission = _c === void 0 ? 'active' : _c; var args = { accountName: accountName, appName: appName, contractName: contractName, permission: permission, whitelistAccount: whitelistAccount }; var action = composeAction(ChainAction.CreateBridge_Whitelist, args); var actions = [action]; return this.transact(actions, broadcast); } // Contributes to account creation for an app by transferring the amount to createbridge with the app name in the memo field // authorizingAccount = an object with account name and permission contributing towards an app // appName = name of the app to contribute // amount = amount to contribute // ramPercentage = RAM% per account the contributor wants to subsidize // totalAccounts = max accounts that can be created with the provided contribution (optional) function transfer(authorizingAccount, appName, amount, ramPercentage, totalAccounts, options) { if (totalAccounts === void 0) { totalAccounts = -1; } var _a = options.contractName, contractName = _a === void 0 ? 'eosio.token' : _a, _b = options.createbridgeAccountName, createbridgeAccountName = _b === void 0 ? 'createbridge' : _b, _c = options.broadcast, broadcast = _c === void 0 ? true : _c; var accountName = authorizingAccount.accountName, _d = authorizingAccount.permission, permission = _d === void 0 ? 'active' : _d; var memo = appName + "," + ramPercentage + "," + totalAccounts; var args = { accountName: accountName, amount: amount, contractName: contractName, createbridgeAccountName: createbridgeAccountName, memo: memo, permission: permission }; var action = composeAction(ChainAction.CreateBridge_Transfer, args); var actions = [action]; return this.transact(actions, broadcast); } // Transfers the remaining balance of a contributor from createbridge back to the contributor // authorizingAccount = an object with account name and permission trying to reclaim the balance // appName = the app name for which the account is trying to reclaim the balance // symbol = symbol of the tokens to be reclaimed. function reclaim(authorizingAccount, appName, symbol, options) { var _a = options.contractName, contractName = _a === void 0 ? 'createbridge' : _a, _b = options.broadcast, broadcast = _b === void 0 ? true : _b; var accountName = authorizingAccount.accountName, _c = authorizingAccount.permission, permission = _c === void 0 ? 'active' : _c; var args = { accountName: accountName, appName: appName, contractName: contractName, permission: permission, symbol: symbol }; var action = composeAction(ChainAction.CreateBridge_Reclaim, args); var actions = [action]; return this.transact(actions, broadcast); } module.exports = { init: init, createNewAccount: createNewAccount, define: define, whitelist: whitelist, transfer: transfer, reclaim: reclaim }; //# sourceMappingURL=createbridge.js.map