subspace/test/test2.js

44 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-08-12 15:10:02 +00:00
const { map, scan, last, distinctUntilChanged } = require('rxjs/operators');
const Web3Eth = require('web3-eth');
const {deployEscrowContract} = require('./utils-web3');
2019-09-27 20:04:01 +00:00
const Subspace = require('../dist/node.js');
2019-08-12 15:10:02 +00:00
let eth = new Web3Eth("ws://localhost:8545");
2019-08-12 15:10:02 +00:00
let myscan = scan((acc, curr) => {
acc.push(curr);
return acc;
}, [])
let mymap = map(arr => arr.reduce((acc, current) => acc + current, 0) / arr.length)
async function run() {
let accounts = await eth.getAccounts();
var EscrowContract = await deployEscrowContract(eth)
2019-08-12 15:10:02 +00:00
await EscrowContract.methods.createEscrow(1, accounts[0], accounts[1]).send({from: accounts[0]})
await EscrowContract.methods.createEscrow(1, accounts[1], accounts[2]).send({from: accounts[0]})
await EscrowContract.methods.createEscrow(1, accounts[1], accounts[0]).send({from: accounts[0]})
await EscrowContract.methods.createEscrow(1, accounts[0], accounts[2]).send({from: accounts[0]})
// EscrowContract.events.getPastEvents('Rating', {fromBlock: 1})
EscrowContract.events.Created({fromBlock: 1}, (err, event) => {
// console.dir("new event")
// console.dir(event)
})
2019-09-27 20:04:01 +00:00
const subspace = new Subspace(eth.currentProvider);
2019-08-12 15:10:02 +00:00
2019-09-27 20:04:01 +00:00
await subspace.init()
2019-08-20 18:14:55 +00:00
console.dir("getting escrows created by " + accounts[0])
2019-08-12 15:10:02 +00:00
2019-09-27 20:04:01 +00:00
// subspace.trackEvent(EscrowContract, 'Created', ((x) => true)).pipe().subscribe((v) => {
subspace.trackEvent(EscrowContract, 'Created', { filter: { buyer: accounts[0] }, fromBlock: 1 }).pipe().subscribe((v) => {
// subspace.trackEvent(EscrowContract, 'Rating', ((x) => true)).pipe(map(x => x.rating)).subscribe((v) => {
2019-08-20 18:14:55 +00:00
console.dir("value is ")
console.dir(v)
2019-08-12 15:10:02 +00:00
});
}
run()