2019-08-19 19:34:22 +00:00
|
|
|
const { map, scan, last, distinctUntilChanged } = require('rxjs/operators');
|
2019-08-22 15:25:26 +00:00
|
|
|
const Web3Eth = require('web3-eth');
|
2019-09-27 20:04:01 +00:00
|
|
|
const Subspace = require('../dist/node.js');
|
2019-08-19 19:34:22 +00:00
|
|
|
|
2019-08-22 15:25:26 +00:00
|
|
|
let eth = new Web3Eth("ws://localhost:8545");
|
2019-08-19 19:34:22 +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 deployContract() {
|
2019-08-22 15:25:26 +00:00
|
|
|
let accounts = await eth.getAccounts();
|
2019-08-19 19:34:22 +00:00
|
|
|
|
|
|
|
// pragma solidity ^0.5.0;
|
|
|
|
// contract SimpleStorage {
|
2019-08-28 20:07:39 +00:00
|
|
|
// mapping(uint => uint) storeMap;
|
2019-08-19 19:34:22 +00:00
|
|
|
// event Test(uint indexed value);
|
2019-08-28 20:07:39 +00:00
|
|
|
// constructor() public {
|
2019-08-19 19:34:22 +00:00
|
|
|
// }
|
2019-08-28 20:07:39 +00:00
|
|
|
|
|
|
|
// function set(uint x, uint y) public {
|
|
|
|
// storeMap[x] = y;
|
2019-08-19 19:34:22 +00:00
|
|
|
// }
|
2019-08-28 20:07:39 +00:00
|
|
|
|
|
|
|
// function get(uint x) public view returns (uint, address) {
|
|
|
|
// return (storeMap[x], msg.sender);
|
2019-08-19 19:34:22 +00:00
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
let abi = [
|
|
|
|
{
|
|
|
|
"constant": false,
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"name": "x",
|
|
|
|
"type": "uint256"
|
2019-08-28 20:07:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "y",
|
|
|
|
"type": "uint256"
|
2019-08-19 19:34:22 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"name": "set",
|
|
|
|
"outputs": [],
|
|
|
|
"payable": false,
|
|
|
|
"stateMutability": "nonpayable",
|
|
|
|
"type": "function"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"constant": true,
|
2019-08-28 20:07:39 +00:00
|
|
|
"inputs": [
|
2019-08-19 19:34:22 +00:00
|
|
|
{
|
2019-08-28 20:07:39 +00:00
|
|
|
"name": "x",
|
2019-08-19 19:34:22 +00:00
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
],
|
2019-08-28 20:07:39 +00:00
|
|
|
"name": "get",
|
|
|
|
"outputs": [
|
2019-08-19 19:34:22 +00:00
|
|
|
{
|
2019-08-28 20:07:39 +00:00
|
|
|
"name": "",
|
2019-08-19 19:34:22 +00:00
|
|
|
"type": "uint256"
|
2019-08-28 20:07:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "",
|
|
|
|
"type": "address"
|
2019-08-19 19:34:22 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"payable": false,
|
2019-08-28 20:07:39 +00:00
|
|
|
"stateMutability": "view",
|
2019-08-19 19:34:22 +00:00
|
|
|
"type": "function"
|
|
|
|
},
|
|
|
|
{
|
2019-08-28 20:07:39 +00:00
|
|
|
"inputs": [],
|
2019-08-19 19:34:22 +00:00
|
|
|
"payable": false,
|
|
|
|
"stateMutability": "nonpayable",
|
|
|
|
"type": "constructor"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"anonymous": false,
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"indexed": true,
|
|
|
|
"name": "value",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"name": "Test",
|
|
|
|
"type": "event"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2019-08-22 15:25:26 +00:00
|
|
|
var contract = new eth.Contract(abi)
|
2019-08-19 19:34:22 +00:00
|
|
|
let instance = await contract.deploy({
|
2019-08-28 20:07:39 +00:00
|
|
|
data: '0x608060405234801561001057600080fd5b5061017c806100206000396000f3fe608060405260043610610046576000357c0100000000000000000000000000000000000000000000000000000000900480631ab06ee51461004b5780639507d39a14610090575b600080fd5b34801561005757600080fd5b5061008e6004803603604081101561006e57600080fd5b810190808035906020019092919080359060200190929190505050610112565b005b34801561009c57600080fd5b506100c9600480360360208110156100b357600080fd5b810190808035906020019092919050505061012d565b604051808381526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390f35b80600080848152602001908152602001600020819055505050565b60008060008084815260200190815260200160002054338090509150915091509156fea165627a7a7230582054f962728d2f5acbfde67516616e1b90e3aca5df27a213cbbabc16387d9af7d90029',
|
|
|
|
arguments: []
|
2019-08-19 19:34:22 +00:00
|
|
|
}).send({
|
|
|
|
from: accounts[0],
|
|
|
|
gas: '4700000'
|
|
|
|
})
|
|
|
|
return instance
|
|
|
|
}
|
|
|
|
|
|
|
|
async function run() {
|
2019-08-22 15:25:26 +00:00
|
|
|
let accounts = await eth.getAccounts();
|
2019-08-19 19:34:22 +00:00
|
|
|
var SimpleStorageContract = await deployContract()
|
|
|
|
console.dir(SimpleStorageContract.options.address)
|
|
|
|
|
|
|
|
setTimeout(async () => {
|
2019-08-28 20:07:39 +00:00
|
|
|
await SimpleStorageContract.methods.set(0, 100).send({ from: accounts[0], gas: 4700000 })
|
|
|
|
await SimpleStorageContract.methods.set(2, 200).send({ from: accounts[0] })
|
|
|
|
await SimpleStorageContract.methods.set(1, 200).send({ from: accounts[0] })
|
|
|
|
await SimpleStorageContract.methods.set(0, 300).send({ from: accounts[0] })
|
|
|
|
await SimpleStorageContract.methods.set(2, 300).send({ from: accounts[0] })
|
|
|
|
await SimpleStorageContract.methods.set(0, 300).send({ from: accounts[0] })
|
|
|
|
}, 2000)
|
2019-08-19 19:34:22 +00:00
|
|
|
|
2019-09-27 20:04:01 +00:00
|
|
|
const subspace = new Subspace(eth.currentProvider);
|
2019-08-19 19:34:22 +00:00
|
|
|
|
2019-09-27 20:04:01 +00:00
|
|
|
await subspace.init();
|
2019-08-19 19:34:22 +00:00
|
|
|
|
2019-09-27 20:04:01 +00:00
|
|
|
subspace.trackProperty(SimpleStorageContract, 'get', [2], {from: "0x0000000000000000000000000000000000000012"} ).pipe().subscribe((v) => {
|
2019-08-20 18:14:55 +00:00
|
|
|
console.dir("value is ")
|
|
|
|
console.dir(v)
|
|
|
|
})
|
2019-08-19 19:34:22 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
run()
|