forked from machinomy/machinomy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
receiverTokens.ts
82 lines (82 loc) · 3.04 KB
/
receiverTokens.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
81
82
// import path from 'path'
// import fs from 'fs-extra'
// 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 payment = require(path.resolve('./payment.json'))
// 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-receiver')
//
// async function run() {
// fs.removeSync(path.resolve('./sender-receiver'))
//
// LOG.info(`PROVIDER = ${PROVIDER}`)
// LOG.info(`MNEMONIC SENDER = ${MNEMONIC_SENDER}`)
// LOG.info(`MNEMONIC RECEIVER = ${MNEMONIC_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 receiverWeb3 = new Web3(provider2)
// const tokenAddress = payment.tokenContract
// const TestToken = contracts.TestToken.contract(receiverWeb3.currentProvider)
// const instanceTestToken = await TestToken.deployed()
// const receiverMachinomy = new Machinomy(receiverAccount, receiverWeb3, {
// databaseUrl: 'nedb://sender-receiver/database.nedb',
// })
//
// LOG.info(`Sender: ${senderAccount}`)
// LOG.info(`Receiver: ${receiverAccount}`)
// LOG.info(`Token address: ${tokenAddress}`)
// LOG.info(`Accept payment: ${JSON.stringify(payment)}`)
//
// LOG.info(
// `Balance of Wallet ${senderAccount} = ${await instanceTestToken.balanceOf(senderAccount)} tokens (+ ${payment.channelValue} tokens deposited in channel).`,
// )
// LOG.info(
// `Balance of Wallet ${receiverAccount} = ${await instanceTestToken.balanceOf(receiverAccount)} tokens.`,
// )
//
// await receiverMachinomy.acceptPayment({
// payment: payment,
// })
//
// LOG.info(`Start closing channel with channelID ${payment.channelId}`)
//
// await receiverMachinomy.close(payment.channelId)
//
// LOG.info(`Channel ${payment.channelId} was successfully closed.`)
// LOG.info(
// `Trace the last transaction via https://rinkeby.etherscan.io/address/${receiverAccount}`,
// )
// LOG.info(`Receiver done.`)
//
// LOG.info(
// `Balance of Wallet ${senderAccount} = ${await instanceTestToken.balanceOf(senderAccount)} tokens (- ${payment.price} tokens).`,
// )
// LOG.info(
// `Balance of Wallet ${receiverAccount} = ${await instanceTestToken.balanceOf(receiverAccount)} tokens (+ ${payment.price} tokens).`,
// )
//
// process.exit(0)
// }
//
// run().catch((err) => {
// console.error(err)
// })