Skip to content

Instantly share code, notes, and snippets.

@PeHo89
Created August 17, 2018 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PeHo89/1a998e89d7fb77d6c7a3a53f9a6b9e38 to your computer and use it in GitHub Desktop.
Save PeHo89/1a998e89d7fb77d6c7a3a53f9a6b9e38 to your computer and use it in GitHub Desktop.
import { MicroRaiden } from '../../microraiden'
let request = require('request');
const WEB3_LOCALHOST: string = 'http://localhost:8545';
const CONTRACT_ADDRESS: string = '0x74434527b8E6C8296506D61d0faF3D18c9e4649A';
const CONTRACT_ABI: any[] = [
{
"constant": false,
"inputs": [
{
"name": "_receiver_address",
"type": "address"
},
{
"name": "_open_block_number",
"type": "uint32"
},
{
"name": "_added_deposit",
"type": "uint192"
}
],
"name": "topUp",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "challenge_period",
"outputs": [
{
"name": "",
"type": "uint32"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_sender_address",
"type": "address"
},
{
"name": "_receiver_address",
"type": "address"
},
{
"name": "_open_block_number",
"type": "uint32"
}
],
"name": "getChannelInfo",
"outputs": [
{
"name": "",
"type": "bytes32"
},
{
"name": "",
"type": "uint192"
},
{
"name": "",
"type": "uint32"
},
{
"name": "",
"type": "uint192"
},
{
"name": "",
"type": "uint192"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_receiver_address",
"type": "address"
},
{
"name": "_open_block_number",
"type": "uint32"
},
{
"name": "_balance",
"type": "uint192"
},
{
"name": "_balance_msg_sig",
"type": "bytes"
}
],
"name": "extractBalanceProofSignature",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_receiver_address",
"type": "address"
},
{
"name": "_open_block_number",
"type": "uint32"
},
{
"name": "_balance",
"type": "uint192"
},
{
"name": "_balance_msg_sig",
"type": "bytes"
},
{
"name": "_closing_sig",
"type": "bytes"
}
],
"name": "cooperativeClose",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_sender_address",
"type": "address"
},
{
"name": "_open_block_number",
"type": "uint32"
},
{
"name": "_balance",
"type": "uint192"
},
{
"name": "_closing_sig",
"type": "bytes"
}
],
"name": "extractClosingSignature",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_trusted_contracts",
"type": "address[]"
}
],
"name": "removeTrustedContracts",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "bytes32"
}
],
"name": "withdrawn_balances",
"outputs": [
{
"name": "",
"type": "uint192"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_receiver_address",
"type": "address"
},
{
"name": "_open_block_number",
"type": "uint32"
},
{
"name": "_balance",
"type": "uint192"
}
],
"name": "uncooperativeClose",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "version",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_receiver_address",
"type": "address"
},
{
"name": "_open_block_number",
"type": "uint32"
}
],
"name": "settle",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "channel_deposit_bugbounty_limit",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "bytes32"
}
],
"name": "closing_requests",
"outputs": [
{
"name": "closing_balance",
"type": "uint192"
},
{
"name": "settle_block_number",
"type": "uint32"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_sender_address",
"type": "address"
},
{
"name": "_receiver_address",
"type": "address"
},
{
"name": "_open_block_number",
"type": "uint32"
},
{
"name": "_added_deposit",
"type": "uint192"
}
],
"name": "topUpDelegate",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "bytes32"
}
],
"name": "channels",
"outputs": [
{
"name": "deposit",
"type": "uint192"
},
{
"name": "open_block_number",
"type": "uint32"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_sender_address",
"type": "address"
},
{
"name": "_receiver_address",
"type": "address"
},
{
"name": "_open_block_number",
"type": "uint32"
}
],
"name": "getKey",
"outputs": [
{
"name": "data",
"type": "bytes32"
}
],
"payable": false,
"stateMutability": "pure",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "owner_address",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_trusted_contracts",
"type": "address[]"
}
],
"name": "addTrustedContracts",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
}
],
"name": "trusted_contracts",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_open_block_number",
"type": "uint32"
},
{
"name": "_balance",
"type": "uint192"
},
{
"name": "_balance_msg_sig",
"type": "bytes"
}
],
"name": "withdraw",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_receiver_address",
"type": "address"
},
{
"name": "_deposit",
"type": "uint192"
}
],
"name": "createChannel",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_sender_address",
"type": "address"
},
{
"name": "_deposit",
"type": "uint256"
},
{
"name": "_data",
"type": "bytes"
}
],
"name": "tokenFallback",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "token",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_sender_address",
"type": "address"
},
{
"name": "_receiver_address",
"type": "address"
},
{
"name": "_deposit",
"type": "uint192"
}
],
"name": "createChannelDelegate",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"name": "_token_address",
"type": "address"
},
{
"name": "_challenge_period",
"type": "uint32"
},
{
"name": "_trusted_contracts",
"type": "address[]"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_sender_address",
"type": "address"
},
{
"indexed": true,
"name": "_receiver_address",
"type": "address"
},
{
"indexed": false,
"name": "_deposit",
"type": "uint192"
}
],
"name": "ChannelCreated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_sender_address",
"type": "address"
},
{
"indexed": true,
"name": "_receiver_address",
"type": "address"
},
{
"indexed": true,
"name": "_open_block_number",
"type": "uint32"
},
{
"indexed": false,
"name": "_added_deposit",
"type": "uint192"
}
],
"name": "ChannelToppedUp",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_sender_address",
"type": "address"
},
{
"indexed": true,
"name": "_receiver_address",
"type": "address"
},
{
"indexed": true,
"name": "_open_block_number",
"type": "uint32"
},
{
"indexed": false,
"name": "_balance",
"type": "uint192"
}
],
"name": "ChannelCloseRequested",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_sender_address",
"type": "address"
},
{
"indexed": true,
"name": "_receiver_address",
"type": "address"
},
{
"indexed": true,
"name": "_open_block_number",
"type": "uint32"
},
{
"indexed": false,
"name": "_balance",
"type": "uint192"
},
{
"indexed": false,
"name": "_receiver_tokens",
"type": "uint192"
}
],
"name": "ChannelSettled",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_sender_address",
"type": "address"
},
{
"indexed": true,
"name": "_receiver_address",
"type": "address"
},
{
"indexed": true,
"name": "_open_block_number",
"type": "uint32"
},
{
"indexed": false,
"name": "_withdrawn_balance",
"type": "uint192"
}
],
"name": "ChannelWithdraw",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_trusted_contract_address",
"type": "address"
},
{
"indexed": false,
"name": "_trusted_status",
"type": "bool"
}
],
"name": "TrustedContract",
"type": "event"
}
];
const TOKEN_ADDRESS: string = '0xFF24D15afb9Eb080c089053be99881dd18aa1090';
const TOKEN_ABI: any[] = [
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_spender",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "mint",
"outputs": [],
"payable": true,
"stateMutability": "payable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "multiplier",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_from",
"type": "address"
},
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [
{
"name": "",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "transferFunds",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "version",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_owner",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "owner_address",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
},
{
"name": "_data",
"type": "bytes"
}
],
"name": "transfer",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_owner",
"type": "address"
},
{
"name": "_spender",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"name": "initial_supply",
"type": "uint256"
},
{
"name": "token_name",
"type": "string"
},
{
"name": "token_symbol",
"type": "string"
},
{
"name": "decimal_units",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_to",
"type": "address"
},
{
"indexed": true,
"name": "_num",
"type": "uint256"
}
],
"name": "Minted",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_from",
"type": "address"
},
{
"indexed": true,
"name": "_to",
"type": "address"
},
{
"indexed": false,
"name": "_value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_owner",
"type": "address"
},
{
"indexed": true,
"name": "_spender",
"type": "address"
},
{
"indexed": false,
"name": "_value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
}
];
const START_BLOCK: number = 2507629;
const SENDER_ADDRESS: string = '0x4f171ad9568e295998182d09a3dbc5db03a19750';
const SENDER_NEW_ADDRESS: string = '0x8156d83aaf0d00b4ca92ede3b6f036c05f1bb5f0';
const RECEIVER_ADDRESS: string = '0x58a08b28dada672f04a20d22e9faf4097cc7e322';
console.log("Application started!");
const uRaiden = new MicroRaiden(WEB3_LOCALHOST, CONTRACT_ADDRESS, CONTRACT_ABI, TOKEN_ADDRESS, TOKEN_ABI, START_BLOCK);
uRaiden.loadChannelFromBlockchain(SENDER_ADDRESS, RECEIVER_ADDRESS)
.then(val => {
console.log(val);
uRaiden.closeChannel().then(res => {
console.log(res);
}).catch(error => {
console.log(error);
});
}).catch(err => {
console.log(err);
});
/*request('http://localhost:5000/echofix/hello', (error, response, body) => {
console.log('error:', error);
console.log('statusCode:', response && response.statusCode);
console.log('body:', body);
});*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment