forked from machinomy/machinomy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsenderTokens.ts
80 lines (80 loc) · 2.7 KB
/
senderTokens.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// import path from 'path'
// import fs from 'fs-extra'
// import BigNumber from 'bignumber.js'
// import Web3 from 'web3'
// import Machinomy from 'machinomy'
// import HDWalletProvider from '@machinomy/hdwallet-provider'
// import Logger from '@machinomy/logger'
// import contracts from '@machinomy/contracts'
//
// const PROVIDER = process.env.PROVIDER || 'https://rinkeby.infura.io'
// const MNEMONIC_SENDER =
// process.env.MNEMONIC_SENDER ||
// 'peanut giggle name tree canoe tube render ketchup survey segment army will'
// const MNEMONIC_RECEIVER =
// process.env.MNEMONIC_RECEIVER ||
// 'dance mutual spike analyst together average reject pudding hazard move fence install'
// const LOG = new Logger('machinomy-sender')
//
// async function run() {
// fs.removeSync(path.resolve('./sender-receiver'))
//
// const provider1 = HDWalletProvider.mnemonic({
// mnemonic: MNEMONIC_SENDER!,
// rpc: PROVIDER,
// })
// const provider2 = HDWalletProvider.mnemonic({
// mnemonic: MNEMONIC_RECEIVER!,
// rpc: PROVIDER,
// })
// const senderAccount = (await provider1.getAddresses())[0]
// const receiverAccount = (await provider2.getAddresses())[0]
// const web3 = new Web3(provider1)
// const channelValue = new BigNumber(20)
// const paymentPrice = new BigNumber(5)
// const instanceTestToken: contracts.TestToken.Contract =
// await contracts.TestToken.contract(provider1).deployed()
// const tokenContract = instanceTestToken.address
//
// LOG.info(`PROVIDER = ${PROVIDER}`)
// LOG.info(`MNEMONIC SENDER = ${MNEMONIC_SENDER}`)
// LOG.info(`MNEMONIC RECEIVER = ${MNEMONIC_RECEIVER}`)
// LOG.info(`Token contract = ${tokenContract}`)
//
// const machinomy = new Machinomy(senderAccount, web3, {
// databaseUrl: 'nedb://sender-receiver/database.nedb',
// })
//
// LOG.info(
// `Start opening Machinomy channel between sender ${senderAccount} and receiver ${receiverAccount} with value ${channelValue} tokens`,
// )
// LOG.info(
// `For remote Ethereum nodes (e.g. Rinkeby or Ropsten) it can taking a 30-60 seconds.`,
// )
//
// await machinomy.open(receiverAccount, channelValue, undefined, tokenContract)
//
// LOG.info(`Channel was opened.`)
// LOG.info(
// `Trace the last transaction via https://rinkeby.etherscan.io/address/${senderAccount}`,
// )
//
// const payment = await machinomy.payment({
// receiver: receiverAccount,
// price: paymentPrice,
// tokenContract: tokenContract,
// })
//
// LOG.info('Payment: ')
// LOG.info(payment.payment)
//
// fs.writeFileSync('payment.json', JSON.stringify(payment.payment))
//
// LOG.info('Sender done.')
//
// process.exit(0)
// }
//
// run().catch((err) => {
// console.error(err)
// })