MCPcopy Create free account
hub / github.com/PolymathNetwork/polymath-core / forcedTransfers

Function forcedTransfers

CLI/commands/transfer_manager.js:149–220  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

147}
148
149async function forcedTransfers() {
150 let options = ['Disable controller', 'Set controller'];
151 let controller = await securityToken.methods.controller().call();
152 if (controller == Issuer.address) {
153 options.push('Force Transfer');
154 }
155 let index = readlineSync.keyInSelect(options, 'What do you want to do?', { cancel: 'RETURN' });
156 let optionSelected = index !== -1 ? options[index] : 'RETURN';
157 console.log('Selected:', optionSelected, '\n');
158 switch (optionSelected) {
159 case 'Disable controller':
160 if (readlineSync.keyInYNStrict()) {
161 let disableControllerAction = securityToken.methods.disableController();
162 await common.sendTransaction(disableControllerAction);
163 console.log(chalk.green(`Forced transfers have been disabled permanently`));
164 }
165 break;
166 case 'Set controller':
167 let controllerAddress = readlineSync.question(`Enter the address for the controller (${Issuer.address}): `, {
168 limit: function (input) {
169 return web3.utils.isAddress(input);
170 },
171 limitMessage: "Must be a valid address",
172 defaultInput: Issuer.address
173 });
174 let setControllerAction = securityToken.methods.setController(controllerAddress);
175 let setControllerReceipt = await common.sendTransaction(setControllerAction);
176 let setControllerEvent = common.getEventFromLogs(securityToken._jsonInterface, setControllerReceipt.logs, 'SetController');
177 console.log(chalk.green(`New controller is ${setControllerEvent._newController}`));
178 break;
179 case 'Force Transfer':
180 let from = readlineSync.question('Enter the address from which to take tokens: ', {
181 limit: function (input) {
182 return web3.utils.isAddress(input);
183 },
184 limitMessage: "Must be a valid address",
185 });
186 let fromBalance = web3.utils.fromWei(await securityToken.methods.balanceOf(from).call());
187 console.log(chalk.yellow(`Balance of ${from}: ${fromBalance} ${tokenSymbol}`));
188 let to = readlineSync.question('Enter address where to send tokens: ', {
189 limit: function (input) {
190 return web3.utils.isAddress(input);
191 },
192 limitMessage: "Must be a valid address",
193 });
194 let toBalance = web3.utils.fromWei(await securityToken.methods.balanceOf(to).call());
195 console.log(chalk.yellow(`Balance of ${to}: ${toBalance} ${tokenSymbol}`));
196 let amount = readlineSync.question('Enter amount of tokens to transfer: ', {
197 limit: function (input) {
198 return parseInt(input) <= parseInt(fromBalance);
199 },
200 limitMessage: `Amount must be less or equal than ${fromBalance} ${tokenSymbol}`,
201 });
202 let data = readlineSync.question('Enter the data to indicate validation: ');
203 let log = readlineSync.question('Enter the data attached to the transfer by controller to emit in event: ');
204 let forceTransferAction = securityToken.methods.forceTransfer(from, to, web3.utils.toWei(amount), web3.utils.asciiToHex(data), web3.utils.asciiToHex(log));
205 let forceTransferReceipt = await common.sendTransaction(forceTransferAction, { factor: 1.5 });
206 let forceTransferEvent = common.getEventFromLogs(securityToken._jsonInterface, forceTransferReceipt.logs, 'ForceTransfer');

Callers 1

executeAppFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected