|
1 | 1 | const CronJob = require('cron').CronJob; |
| 2 | +const neo = require('neo-api-js'); |
| 3 | +const Neon = require('neon-js'); |
2 | 4 |
|
3 | | -exports.create_savings = function (data) { |
| 5 | +const config = require('../config'); |
| 6 | +const NodeService = require("../services/node"); |
4 | 7 |
|
| 8 | +exports.open_savings = function (amount) { |
| 9 | + const account = Neon.getAccountFromWIFKey(config.wif); |
| 10 | + const scriptHash = Neon.getScriptHashFromAddress(config.contractAddress); |
| 11 | + const invoke = { operation: 'create', scriptHash }; |
| 12 | + const intents = [{ assetId: Neon.ASSETS['NEO'], value: amount, scriptHash }]; |
| 13 | + const gasCost = 0.5; |
| 14 | + let signedTx; |
| 15 | + console.log("HERE"); |
| 16 | + NodeService.getBalance(config.contractAddress).then((response) => { |
| 17 | + // const balance = response.result.balance; |
| 18 | + console.log("Balance is:", response); |
| 19 | + const unsignedTx = Neon.create.invocation(account.publicKey, response, intents, invoke, gasCost, { version: 1 }); |
| 20 | + signedTx = Neon.signTransaction(unsignedTx, account.privateKey); |
| 21 | + const hexTx = Neon.serializeTransaction(signedTx); |
| 22 | + return Neon.queryRPC(net, 'sendrawtransaction', [hexTx], 4); |
| 23 | + }).catch(function(error) { |
| 24 | + console.log(error); |
| 25 | + }).then((res) => { |
| 26 | + if (res.result === true) { |
| 27 | + res.txid = Neon.getTransactionHash(signedTx) |
| 28 | + } |
| 29 | + return res |
| 30 | + }) |
5 | 31 | }; |
6 | 32 |
|
7 | 33 | exports.start_payment_cron = function (until, period) { |
| 34 | + /* |
| 35 | + Should use pollingPolicy? |
| 36 | + const pollingPolicy = neo.service.createPollingPolicy(interval); |
| 37 | + pollingPolicy.onInterval(function () { |
| 38 | + });*/ |
| 39 | + |
8 | 40 | const endDate = new Date(until); |
9 | 41 | const currentDate = new Date(); |
10 | 42 | const hours = currentDate.getHours(); |
|
0 commit comments