UNPKG

8.39 kBJavaScriptView Raw
1"use strict";
2/* Public */
3// Initializes createbridge with the following details:
4// Only the createbridge account can call this action
5// symbol = the core token of the chain or the token used to pay for new user accounts of the chain
6// precision = precision of the core token of the chain
7// newAccountContract = the contract to call for new account action
8// minimumRAM = minimum bytes of RAM to put in a new account created on the chain
9function init(symbol, precision, newAccountContract, minimumRAM, options) {
10 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;
11 var chainSymbol = precision + "," + symbol;
12 var actions = [{
13 account: contractName,
14 name: 'init',
15 authorization: [{
16 actor: contractName,
17 permission: permission,
18 }],
19 data: {
20 symbol: chainSymbol,
21 newaccountcontract: newAccountContract,
22 minimumram: minimumRAM,
23 }
24 }];
25 return this.transact(actions, broadcast);
26}
27// Registers an app with the createbridge contract. Called with the following parameter:
28// authorizingAccount = an object with account name and permission to be registered as the owner of the app
29// appName: = the string/account name representing the app
30// ram: = bytes of ram to put in the new user account created for the app (defaults to 4kb)
31// net = amount to be staked for net
32// cpu = amount to be staked for cpu
33// airdropContract = name of the airdrop contract
34// airdropToken = total number of tokens to be airdropped
35// airdroplimit = number of tokens to be airdropped to the newly created account
36function define(authorizingAccount, appName, ram, net, cpu, options) {
37 if (ram === void 0) { ram = 4096; }
38 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;
39 var accountName = authorizingAccount.accountName, _c = authorizingAccount.permission, permission = _c === void 0 ? "active" : _c;
40 var airdrop = {
41 contract: airdropContract,
42 tokens: airdropToken,
43 limit: airdropLimit
44 };
45 var actions = [{
46 account: contractName,
47 name: 'define',
48 authorization: [{
49 actor: accountName,
50 permission: permission,
51 }],
52 data: {
53 owner: accountName,
54 dapp: appName,
55 ram_bytes: ram,
56 net: net,
57 cpu: cpu,
58 airdrop: airdrop,
59 }
60 }];
61 return this.transact(actions, broadcast);
62}
63// Creates a new user account. It also airdrops custom dapp tokens to the new user account if an app owner has opted for airdrops
64// authorizingAccount = an object with account name and permission of the account paying for the balance left after getting the donation from the app contributors
65// keys = owner key and active key for the new account
66// origin = the string representing the app to create the new user account for. For ex- everipedia.org, lumeos
67function createNewAccount(authorizingAccount, keys, options) {
68 var accountName = authorizingAccount.accountName, permission = authorizingAccount.permission;
69 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;
70 var actions = [{
71 account: contractName,
72 name: 'create',
73 authorization: [{
74 actor: accountName,
75 permission: permission,
76 }],
77 data: {
78 memo: accountName,
79 account: oreAccountName,
80 ownerkey: keys.publicKeys.owner,
81 activekey: keys.publicKeys.active,
82 origin: origin
83 }
84 }];
85 return this.transact(actions, broadcast);
86}
87// Owner account of an app can whitelist other accounts.
88// authorizingAccount = an object with account name and permission contributing towards an app
89// whitelistAccount = account name to be whitelisted to create accounts on behalf of the app
90function whitelist(authorizingAccount, whitelistAccount, appName, options) {
91 var _a = options.contractName, contractName = _a === void 0 ? "createbridge" : _a, _b = options.broadcast, broadcast = _b === void 0 ? true : _b;
92 var accountName = authorizingAccount.accountName, _c = authorizingAccount.permission, permission = _c === void 0 ? "active" : _c;
93 var actions = [{
94 account: contractName,
95 name: 'whitelist',
96 authorization: [{
97 actor: accountName,
98 permission: permission,
99 }],
100 data: {
101 owner: accountName,
102 account: whitelistAccount,
103 dapp: appName,
104 }
105 }];
106 return this.transact(actions, broadcast);
107}
108// Contributes to account creation for an app by transferring the amount to createbridge with the app name in the memo field
109// authorizingAccount = an object with account name and permission contributing towards an app
110// appName = name of the app to contribute
111// amount = amount to contribute
112// ramPercentage = RAM% per account the contributor wants to subsidize
113// totalAccounts = max accounts that can be created with the provided contribution (optional)
114function transfer(authorizingAccount, appName, amount, ramPercentage, totalAccounts, options) {
115 if (totalAccounts === void 0) { totalAccounts = -1; }
116 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;
117 var accountName = authorizingAccount.accountName, _d = authorizingAccount.permission, permission = _d === void 0 ? "active" : _d;
118 var memo = appName + "," + ramPercentage + "," + totalAccounts;
119 var actions = [{
120 account: contractName,
121 name: 'transfer',
122 authorization: [{
123 actor: accountName,
124 permission: permission,
125 }],
126 data: {
127 from: accountName,
128 to: createbridgeAccountName,
129 quantity: amount,
130 memo: memo,
131 }
132 }];
133 return this.transact(actions, broadcast);
134}
135// Transfers the remaining balance of a contributor from createbridge back to the contributor
136// authorizingAccount = an object with account name and permission trying to reclaim the balance
137// appName = the app name for which the account is trying to reclaim the balance
138// symbol = symbol of the tokens to be reclaimed.
139function reclaim(authorizingAccount, appName, symbol, options) {
140 var _a = options.contractName, contractName = _a === void 0 ? "createbridge" : _a, _b = options.broadcast, broadcast = _b === void 0 ? true : _b;
141 var accountName = authorizingAccount.accountName, _c = authorizingAccount.permission, permission = _c === void 0 ? "active" : _c;
142 var actions = [{
143 account: contractName,
144 name: 'reclaim',
145 authorization: [{
146 actor: accountName,
147 permission: permission,
148 }],
149 data: {
150 reclaimer: accountName,
151 dapp: appName,
152 sym: symbol,
153 }
154 }];
155 return this.transact(actions, broadcast);
156}
157module.exports = {
158 init: init,
159 createNewAccount: createNewAccount,
160 define: define,
161 whitelist: whitelist,
162 transfer: transfer,
163 reclaim: reclaim,
164};
165//# sourceMappingURL=createbridge.js.map
\No newline at end of file