Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
53 lines (41 sloc) 1.64 KB
import * as path from 'path'
import * as fs from 'fs-extra'
import BigNumber from 'bignumber.js'
import * as Web3 from 'web3'
import Machinomy from 'machinomy'
import HDWalletProvider from '@machinomy/hdwallet-provider'
import Logger from '@machinomy/logger'
const payment = require(path.resolve('./payment.json'))
const PROVIDER = process.env.PROVIDER || 'https://rinkeby.infura.io'
const MNEMONIC = process.env.MNEMONIC || 'peanut giggle name tree canoe tube render ketchup survey segment army will'
const LOG = new Logger('machinomy-receiver')
async function run () {
fs.removeSync(path.resolve('./sender-receiver'))
LOG.info(`PROVIDER = ${PROVIDER}`)
LOG.info(`MNEMONIC = ${MNEMONIC}`)
const provider = HDWalletProvider.http(MNEMONIC, PROVIDER, 2)
const receiverAccount = await provider.getAddress(1)
const receiverWeb3 = new Web3(provider)
const minimumChannelAmount = new BigNumber(1).shift(4)
const receiverMachinomy = new Machinomy(
receiverAccount,
receiverWeb3, {
databaseUrl: 'nedb://sender-receiver/database.nedb',
minimumChannelAmount: minimumChannelAmount
}
)
LOG.info(`Receiver: ${receiverAccount}`)
LOG.info(`Accept payment: ${JSON.stringify(payment)}`)
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.`)
process.exit(0)
}
run().catch(err => {
console.error(err)
})
You can’t perform that action at this time.