<!DOCTYPEhtml><html><head><scripttype="text/javascript"src="../dist/web3_hpb.js"></script><scripttype="text/javascript">varweb3_hpb=require('web3_hpb');varweb3_hpb=newweb3_hpb();web3_hpb.setProvider(newweb3_hpb.providers.HttpProvider("http://localhost:8545"));// solidity code codevarsource=""+"pragma solidity ^0.4.6;"+"contract test {\n"+" function multiply(uint a) constant returns(uint d) {\n"+" return a * 7;\n"+" }\n"+"}\n";varcompiled=web3_hpb.hpb.compile.solidity(source);varcode=compiled.code;// contract json abi, this is autogenerated using solc CLIvarabi=compiled.info.abiDefinition;varmyContract;functioncreateExampleContract(){// hide create buttondocument.getElementById('create').style.visibility='hidden';document.getElementById('code').innerText=code;// let's assume that coinbase is our accountweb3_hpb.hpb.defaultAccount=web3_hpb.hpb.coinbase;// create contractdocument.getElementById('status').innerText="transaction sent, waiting for confirmation";web3_hpb.hpb.contract(abi).new({data:code},function(err,contract){if(err){console.error(err);return;// callback fires twice, we only want the second call when the contract is deployed}elseif(contract.address){myContract=contract;console.log('address: '+myContract.address);document.getElementById('status').innerText='Mined!';document.getElementById('call').style.visibility='visible';}});}functioncallExampleContract(){// this should be generated by hpbervarparam=parseInt(document.getElementById('value').value);// call the contractvarres=myContract.multiply(param);document.getElementById('result').innerText=res.toString(10);}</script></head><body><h1>contract</h1><divid="code"></div> <divid="status"></div><divid='create'><buttontype="button"onClick="createExampleContract();">createexamplecontract</button></div><divid='call'style='visibility: hidden;'><inputtype="number"id="value"onkeyup='callExampleContract()'></input></div><divid="result"></div></body></html>
<!DOCTYPEhtml><html><head><scripttype="text/javascript"src="../dist/web3_hpb.js"></script><scripttype="text/javascript">varweb3_hpb=require('web3_hpb');varweb3_hpb=newweb3_hpb();web3_hpb.setProvider(newweb3_hpb.providers.HttpProvider("http://localhost:8545"));// solidity code codevarsource=""+"pragma solidity ^0.4.6;"+"contract test {\n"+" function take(uint[] a, uint b) constant returns(uint d) {\n"+" return a[b];\n"+" }\n"+"}\n";varcompiled=web3_hpb.hpb.compile.solidity(source);varcode=compiled.code;// contract json abi, this is autogenerated using solc CLIvarabi=compiled.info.abiDefinition;varmyContract;functioncreateExampleContract(){// hide create buttondocument.getElementById('create').style.visibility='hidden';document.getElementById('code').innerText=code;// let's assume that coinbase is our accountweb3_hpb.hpb.defaultAccount=web3_hpb.hpb.coinbase;// create contractdocument.getElementById('status').innerText="transaction sent, waiting for confirmation";web3_hpb.hpb.contract(abi).new({data:code},function(err,contract){if(err){console.error(err);return;// callback fires twice, we only want the second call when the contract is deployed}elseif(contract.address){myContract=contract;console.log('address: '+myContract.address);document.getElementById('status').innerText='Mined!';document.getElementById('call').style.visibility='visible';}});}functioncallExampleContract(){// this should be generated by hpbervarparam=parseInt(document.getElementById('value').value);// call the contractvarres=myContract.take([0,6,5,2,1,5,6],param);document.getElementById('result').innerText=res.toString(10);}</script></head><body><h1>contract</h1><divid="code"></div> <divid="status"></div><divid='create'><buttontype="button"onClick="createExampleContract();">createexamplecontract</button></div><divid='call'style='visibility: hidden;'><div>vararray=[0,6,5,2,1,5,6];</div><div>varx=array[<inputtype="number"id="value"onkeyup='callExampleContract()'></input>];</div></div><divid="result"></div></body></html>
<!DOCTYPEhtml><html><head><scripttype="text/javascript"src="../dist/web3_hpb.js"></script><scripttype="text/javascript">varweb3_hpb=require('web3_hpb');varweb3_hpb=newweb3_hpb();web3_hpb.setProvider(newweb3_hpb.providers.HttpProvider('http://localhost:8545'));varsource=""+"pragma solidity ^0.4.6;"+"contract Contract { "+" event Incremented(bool indexed odd, uint x); "+" function Contract() { "+" x = 70; "+" } "+" function inc() { "+" ++x; "+" Incremented(x % 2 == 1, x); "+" } "+" uint x; "+"}";varcompiled=web3_hpb.hpb.compile.solidity(source);varcode=compiled.code;varabi=compiled.info.abiDefinition;varaddress;varcontract;varinc;varupdate=function(err,x){document.getElementById('result').textContent=JSON.stringify(x,null,2);};varcreateContract=function(){// let's assume that we have a private key to coinbase ;)web3_hpb.hpb.defaultAccount=web3_hpb.hpb.coinbase;document.getElementById('create').style.visibility='hidden';document.getElementById('status').innerText="transaction sent, waiting for confirmation";web3_hpb.hpb.contract(abi).new({data:code},function(err,c){if(err){console.error(err);return;// callback fires twice, we only want the second call when the contract is deployed}elseif(c.address){contract=c;console.log('address: '+contract.address);document.getElementById('status').innerText='Mined!';document.getElementById('call').style.visibility='visible';inc=contract.Incremented({odd:true},update);}});};varcounter=0;varcallContract=function(){counter++;varall=70+counter;document.getElementById('count').innerText='Transaction sent '+counter+' times. '+'Expected x value is: '+(all-(all%2?0:1))+' '+'Waiting for the blocks to be mined...';contract.inc();};</script></head><body><divid="status"></div><div><buttonid="create"type="button"onClick="createContract();">createcontract</button></div><div><buttonid="call"style="visibility: hidden;"type="button"onClick="callContract();">test1</button></div><divid='count'></div><divid="result"></div></body>
<!DOCTYPEhtml><html><head><linkrel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"><scriptsrc="https://code.jquery.com/jquery-2.1.4.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script><scripttype="text/javascript"src="../dist/web3_hpb.js"></script><scripttype="text/javascript">varweb3_hpb=require('web3_hpb');varweb3_hpb=newweb3_hpb();varBigNumber=require('bignumber.js');web3_hpb.setProvider(newweb3_hpb.providers.HttpProvider("http://localhost:8545"));varfrom=web3_hpb.hpb.coinbase;web3_hpb.hpb.defaultAccount=from;varnameregAbi=[{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"name","outputs":[{"name":"o_name","type":"bytes32"}],"type":"function"},{"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"owner","outputs":[{"name":"","type":"address"}],"type":"function"},{"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"content","outputs":[{"name":"","type":"bytes32"}],"type":"function"},{"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"addr","outputs":[{"name":"","type":"address"}],"type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"bytes32"}],"name":"reserve","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"subRegistrar","outputs":[{"name":"o_subRegistrar","type":"address"}],"type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_newOwner","type":"address"}],"name":"transfer","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_registrar","type":"address"}],"name":"setSubRegistrar","outputs":[],"type":"function"},{"constant":false,"inputs":[],"name":"Registrar","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_a","type":"address"},{"name":"_primary","type":"bool"}],"name":"setAddress","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_content","type":"bytes32"}],"name":"setContent","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"bytes32"}],"name":"disown","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"register","outputs":[{"name":"","type":"address"}],"type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"name","type":"bytes32"}],"name":"Changed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"name","type":"bytes32"},{"indexed":true,"name":"addr","type":"address"}],"name":"PrimaryChanged","type":"event"}];vardepositAbi=[{"constant":false,"inputs":[{"name":"name","type":"bytes32"}],"name":"deposit","outputs":[],"type":"function"}];varNamereg=web3_hpb.hpb.contract(nameregAbi);varDeposit=web3_hpb.hpb.contract(depositAbi);varnamereg=web3_hpb.hpb.ibanNamereg;vardeposit;variban;functionvalidateNamereg(){varaddress=document.getElementById('namereg').value;varok=web3_hpb.isAddress(address)||address==='default';if(ok){namereg=address==='default'?web3_hpb.hpb.ibanNamereg:Namereg.at(address);document.getElementById('nameregValidation').innerText='ok!';}else{document.getElementById('nameregValidation').innerText='namereg address is incorrect!';}returnok;};functiononNameregKeyUp(){updateIBAN(validateNamereg());onExchangeKeyUp();};functionvalidateExchange(){varexchange=document.getElementById('exchange').value;varok=/^[0-9A-Z]{4}$/.test(exchange);if(ok){varaddress=namereg.addr(exchange);deposit=Deposit.at(address);document.getElementById('exchangeValidation').innerText='ok! address of exchange: '+address;}else{document.getElementById('exchangeValidation').innerText='exchange id is incorrect';}returnok;};functiononExchangeKeyUp(){updateIBAN(validateExchange());};functionvalidateClient(){varclient=document.getElementById('client').value;varok=/^[0-9A-Z]{9}$/.test(client);if(ok){document.getElementById('clientValidation').innerText='ok!';}else{document.getElementById('clientValidation').innerText='client id is incorrect';}returnok;};functiononClientKeyUp(){updateIBAN(validateClient());};functionvalidateValue(){try{varvalue=document.getElementById('value').value;varbnValue=newBigNumber(value);document.getElementById('valueValidation').innerText=bnValue.toString(10);returntrue;}catch(err){document.getElementById('valueValidation').innerText='Value is incorrect, cannot parse';returnfalse;}};functiononValueKeyUp(){validateValue();};functionvalidateIBAN(){if(!iban.isValid()){returndocument.getElementById('ibanValidation').innerText=' - IBAN number is incorrect';}document.getElementById('ibanValidation').innerText=' - IBAN number correct';};functionupdateIBAN(ok){varexchangeId=document.getElementById('exchange').value;varclientId=document.getElementById('client').value;iban=web3_hpb.hpb.iban.createIndirect({institution:exchangeId,identifier:clientId});document.getElementById('iban').innerText=iban.toString();validateIBAN();};functiontransfer(){varvalue=newBigNumber(document.getElementById('value').value);varexchange=document.getElementById('exchange').value;varclient=document.getElementById('client').value;deposit.deposit(web3_hpb.fromAscii(client),{value:value});displayTransfer("deposited client's "+client+" funds "+value.toString(10)+" to exchange "+exchange);};functiondisplayTransfer(text){varnode=document.createElement('li');vartextnode=document.createTextNode(text);node.appendChild(textnode);document.getElementById('transfers').appendChild(node);}</script></head><body><divclass="col-lg-12"><i>ThispageexpectsghpbwithJSON-RPCrunningatport8545</i><divclass="page-header"><h1>ICAPtransfer</h1></div><divclass="col-lg-6"><divclass="well"><legendclass="lead">nameregaddress</legend><small>eg.0x436474facc88948696b371052a1befb801f003caor'default')</small><divclass="form-group"><inputclass="form-control"type="text"id="namereg"onkeyup='onNameregKeyUp()'value="default"></input><textid="nameregValidation"></text></div><legendclass="lead">exchangeidentifier</legend><small>eg.WYWY</small><divclass="form-group"><inputclass="form-control"type="text"id="exchange"onkeyup='onExchangeKeyUp()'></input><textid="exchangeValidation"></text></div><legendclass="lead">clientidentifier</legend><small>eg.GAVOFYORK</small><divclass="form-group"><inputclass="form-control"type="text"id="client"onkeyup='onClientKeyUp()'></input><textid="clientValidation"></text></div><legendclass="lead">value</legend><small>eg.100</small><divclass="form-group"><inputclass="form-control"type="text"id="value"onkeyup='onValueKeyUp()'></input><textid="valueValidation"></text></div><legendclass="lead">IBAN:</legend><divclass="form-group"><textid="iban"></text><textid="ibanValidation"></text></div><div><buttonclass="btn btn-default"id="transfer"type="button"onClick="transfer()">Transfer!</button><textid="transferValidation"></text></div></div></div><divclass="col-lg-6"><divclass="well"><div><legendclass="lead">transfers</legend></div><div><ulid='transfers'></ul></div></div></div></div></body></html>
<!DOCTYPEhtml><html><head><scripttype="text/javascript"src="../dist/web3_hpb.js"></script><scripttype="text/javascript">varweb3_hpb=require('web3_hpb');varweb3_hpb=newweb3_hpb();web3_hpb.setProvider(newweb3_hpb.providers.HttpProvider("http://localhost:8545"));varfrom=web3_hpb.hpb.coinbase;web3_hpb.hpb.defaultAccount=from;window.onload=function(){varfilter=web3_hpb.hpb.namereg().Changed();filter.watch(function(err,event){// live update all fieldsonAddressKeyUp();onNameKeyUp();onRegisterOwnerKeyUp();});};functionregisterOwner(){varname=document.getElementById('registerOwner').value;web3_hpb.hpb.namereg().reserve(name);document.getElementById('nameAvailability').innerText+=' Registering name in progress, please wait...';};functionchangeAddress(){varname=document.getElementById('registerOwner').value;varaddress=document.getElementById('newAddress').value;web3_hpb.hpb.namereg().setAddress(name,address,true);document.getElementById('currentAddress').innerText+=' Changing address in progress. Please wait.';};functiononRegisterOwnerKeyUp(){varname=document.getElementById('registerOwner').value;varowner=web3_hpb.hpb.namereg().owner(name)document.getElementById('currentAddress').innerText=web3_hpb.hpb.namereg().addr(name);if(owner!=='0x0000000000000000000000000000000000000000'){if(owner===from){document.getElementById('nameAvailability').innerText="This name is already owned by you "+owner;}else{document.getElementById('nameAvailability').innerText="This name is not available. It's already registered by "+owner;}return;}document.getElementById('nameAvailability').innerText="This name is available. You can register it.";};functiononAddressKeyUp(){varaddress=document.getElementById('address').value;document.getElementById('nameOf').innerText=web3_hpb.hpb.namereg().name(address);};functiononNameKeyUp(){varname=document.getElementById('name').value;document.getElementById('addressOf').innerText=web3_hpb.hpb.namereg().addr(name);};</script></head><body><i>Thisexampleshowsonlypartofnameregfunctionalities.Nameregcontractisavailable<ahref="https://github.com/hpber/dapp-bin/blob/master/GlobalRegistrar/contract.sol">here</a></i><h1>Namereg</h1><h3>Searchforname</h3><div><text>Address:</text><inputtype="text"id="address"onkeyup='onAddressKeyUp()'></input><text>Name:</text><textid="nameOf"></text></div><h3>Searchforaddress</h3><div><text>Name:</text><inputtype="text"id="name"onkeyup='onNameKeyUp()'></input><text>Address:</text><textid="addressOf"></text></div><h3>Registername</h3><div><text>Checkifnameisavailable:</text><inputtype="text"id="registerOwner"onkeyup='onRegisterOwnerKeyUp()'></input><textid='nameAvailability'></text></div><div><buttonid="registerOwnerButton"type="button"onClick="registerOwner()">Register!</button></div><h3></h3><i>Ifyouownthename,youcanalsochangetheaddressitpointsto</i><div><text>Address:</text><inputtype="text"id="newAddress"></input><buttonid="changeAddress"type="button"onClick="changeAddress()">Changeaddress!</button><text>Currentaddress:</text><textid="currentAddress"></text></div></body></html>
varweb3_hpb=require('../index.js');varhpbURL="";vardefaultAc="";vardefaultAcPWD="";varsignatureContractCodeReadable="\n\tcontract SignatureVerifier {\n\t\tfunction verify( bytes32 hash, uint8 v, bytes32 r, bytes32 s) \n"+"\t\tconstant returns(address returnAddress) {\n \t\t\treturnAddress = ecrecover(hash, v, r, s);\n\t\t}\n\t}\n\n";varsigContractInstance=null;varsigContractAddress="";varsigContractInstance=null;varstrAbi='[{"constant":true,"inputs":[{"name":"hash","type":"bytes32"},{"name":"v","type":"uint8"},{"name":"r","type":"bytes32"},{"name":"s","type":"bytes32"}],"name":"verify","outputs":[{"name":"returnAddress","type":"address"}],"payable":false,"type":"function"}]';varsignMessage="";varhpbweb3_hpb=null;functionsetContractAddress(conAddress){sigContractAddress=conAddress;}functionsetAccount(act){defaultAc=act;}functionsetPassword(pwd){defaultAcPWD=pwd;}functionsetHpbURL(url){hpbURL=url;}functionsetMessage(msg){signMessage=msg;}functioninitializeHpbConnection(){if(hpbweb3_hpb!=null&&hpbweb3_hpb.isConnected()==true){returntrue;}hpbweb3_hpb=newweb3_hpb(newweb3_hpb.providers.HttpProvider(hpbURL));if(hpbweb3_hpb.isConnected()==true){if(defaultAc==''){defaultAc=hpbweb3_hpb.hpb.accounts[1];}returntrue;}returnfalse;}functionunlockAccount(acAddress){if(acAddress!=undefined&&acAddress!=null){varstate=hpbweb3_hpb.personal.unlockAccount(defaultAc,defaultAcPWD,100);returnstate;}returnfalse;}functioninitializeContract(){initializeHpbConnection();if(hpbweb3_hpb.isConnected()==false){return;}varabi=JSON.parse(strAbi);varcontract=hpbweb3_hpb.hpb.contract(abi);sigContractInstance=contract.at(sigContractAddress)}functionsignMessage(message){initializeHpbConnection();if(hpbweb3_hpb.isConnected()==false){returnfalse;}varstate=unlockAccount(defaultAc);constmsg=newBuffer(message);constsig=hpbweb3_hpb.hpb.sign(defaultAc,'0x'+msg.toString('hex'));returnsig;}functionverifySignedByAc(message,sig){initializeHpbConnection();if(hpbweb3_hpb.isConnected()==false){returnfalse;}initializeContract();constres=splitSig(sig);// Unfortunately Ghpb client adds this line to the message as a prefix while signing// So while finding who signed it we need to prefix this part constprefix=newBuffer("\x19Hpb Signed Message:\n");constmsg=newBuffer(message);constprefixedMsg=hpbweb3_hpb.sha3(Buffer.concat([prefix,newBuffer(String(msg.length)),msg]).toString('utf8'));varstrPrefixedMsg=prefixedMsg;varfinalAddress=sigContractInstance.verify.call(strPrefixedMsg,res.v,res.r,'0x'+res.s);returnfinalAddress;}functionsplitSig(sig){return{v:hpbweb3_hpb.toDecimal('0x'+sig.slice(130,132)),r:sig.slice(0,66),s:sig.slice(66,130)}}functionsign(){varmessage=document.getElementById('txtMessage').value;varsignMsg=signMessage(message);document.getElementById('dvSig').innerText=signMsg;}functionverify(){varmessage=document.getElementById('txtMessage').value;varactAddr=verifySignedByAc(message,document.getElementById('dvSig').innerText);document.getElementById('dvSignedBy').innerText=actAddr;}functionexecute(){console.log("\n\n**********************************************************************");console.log("Steps to Run");console.log("**********************************************************************");console.log("1. Deploy the following contract in your hpber environment");console.log(signatureContractCodeReadable);console.log("2. Set the following parameters (i.e. at the end of the code)");console.log("\ta. Hpb URL");console.log("\tb. Hpb Account Address");console.log("\tc. Hpb Account Passphrase");console.log("\td. Signature Contract Address");console.log("\te. Message for signing");console.log("**********************************************************************");if(hpbURL==''){console.log("Error: Hpb URL is not specified");return;}if(defaultAc==''){console.log("Error: Account Address is not specified");return;}if(defaultAcPWD==''){console.log("Error: Account password is not specified");return;}if(sigContractAddress==''){console.log("Error: Signature Contract Address is not specified");return;}if(signMessage==''){console.log("Error: Message for signing is not specified");return;}console.log("Following parameters applied");console.log("\ta. Hpb URL :",hpbURL);console.log("\tb. Hpb Account Address :",defaultAc);console.log("\tc. Hpb Account Passphrase :",defaultAcPWD);console.log("\td. Signature Contract Address :",sigContractAddress);console.log("\te. Message for signing :",signMessage);console.log("**********************************************************************");console.log("Result");console.log("**********************************************************************");varsig=signMessage(signMessage);console.log("Signature");console.log(sig);varaddr=verifySignedByAc(signMessage,sig);console.log("Signed By");console.log(addr);console.log("**********************************************************************");console.log("Exit");console.log("**********************************************************************");}// Please uncomment the below listed three lines of code and provide the required values// Value 1- Please provide the hpber account address which you want to use to perform the operation//setAccount('<Provide the account address>');// Value 2- Please provide the password of the accound to be used //setPassword('<Provide the password>');// Value 3- Please update the address of the contract after deployment// The contract code is made available at the top under signatureContractCodeReadable variable// Please deploy the contract and update the contract address here//setContractAddress('<Provide the deployed contract address>');// Value 4- If required please update with a different messagesetHpbURL('http://localhost:8545');// Value 5- If required please update with a Hpb URLsetMessage('This the test sign message');execute();
Or if you want to clone the github repository (wget need to be installed first) :
123456
git clone https://github.com/ethereum/remix-ide.git
git clone https://github.com/ethereum/remix.git # only if you plan to link remix and remix-ide repositories and develop on it.
cd remix-ide
npm install
npm run setupremix # only if you plan to link remix and remix-ide repositories and develop on it.
npm start
Then open your text editor and start developing. The browser will automatically refresh when files are saved.
Most of the the time working with other modules (like debugger etc.) hosted in the Remix repository is not needed.
Troubleshooting building
Some things to consider if you have trouble building the package:
Make sure that you have the correct version of node, npm and nvm. You can find the version that is tested on Travis CI by looking at the log in the build results.
Run:
123
node --version
npm --version
nvm --version
In Debian based OS such as Ubuntu 14.04LTS you may need to run apt-get install build-essential. After installing build-essential run npm rebuild.
Unit Testing
Register new unit test files in test/index.js. The tests are written using tape.
Run the unit tests via: npm test
For local headless browser tests run npm run test-browser (requires Selenium to be installed – can be done with npm run selenium-install)
Running unit tests via npm test requires at least node v7.0.0
Browser Testing
To run the Selenium tests via Nightwatch serve the app through a local web server:
1
npm run serve # starts web server at localhost:8080
Then you will need to either:
1.Have a Selenium server running locally on port 4444.
1
Run: npm run test-browser
2.Or, install and run SauceConnect.
12
Run: sc -u <USERNAME> -k <ACCESS_KEY> (see .travis.yml for values)
Run: npm run browser-test-sc
Usage as a Chrome Extension
If you would like to use this as a Chrome extension, you must either build it first or pull from the gh-pages branch, both described above. After that, follow these steps:
1234
1.Browse to chrome://extensions/
2.Make sure 'Developer mode' has been checked
3.Click 'Load unpacked extension...' to pop up a file-selection dialog
4.Select your remix-ide folder
Documentation
To see details about how to use Remix for developing and/or debugging Solidity contracts, please see our documentation page
https://remix.readthedocs.io/en/latest/
//指定使用solidity开发语言版本
pragma solidity ^0.4.19;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
//基本的算术方法库
//乘
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
//除
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
//减
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
//加
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
//总供给量,也就是发币总量
uint256 public totalSupply;
//查询指定地址余额
function balanceOf(address who) public view returns (uint256);
//推荐的转账方法可以安全写入
function transfer(address to, uint256 value) public returns (bool);
//记录日志
//address indexed fromaddress indexed to, uint256 value:
event Transfer(address indexed from, address indexed to, uint256 value);
}
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
contract ERC20 is ERC20Basic {
//, _owner _spender查询能够从地址 _owner 提出的代币数量
function allowance(address owner, address spender) public view returns (uint256);
// A-B从地址 _from 转移代币到地址 _to,必须触发 Transfer 事件
function transferFrom(address from, address to, uint256 value) public returns (bool);
// _spender _value成功调用 approve 时触发
function approve(address spender, uint256 value) public returns (bool);
//触发事件记录日志
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/
contract BasicToken is ERC20Basic {
//SafeMathLibrary,
using SafeMath for uint256;
//
mapping(address => uint256) balances;
//_valuetoken_to
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
//require
//address(0) 必须是有效地址
require(_to != address(0));
//balances:
//msg.sender
//发送者余额不为0
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
//发送者余额扣减
balances[msg.sender] = balances[msg.sender].sub(_value);
//接受者余额增加
balances[_to] = balances[_to].add(_value);
//进行交易
Transfer(msg.sender, _to, _value);
return true;
}
//// balanceOffunctionbalanceOf(address _owner)constantreturns(uint256 balance)
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
}
/**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
*/
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
}
/// @title UFO Protocol Token.
/// For more information about this token, please visit http://www.banyanbbt.org
contract UFOToken is StandardToken {
string public name;
string public symbol;
uint public decimals;
/**
* CONSTRUCTOR
*
* @dev Initialize the UFO Token
*/
function UFOToken() public {
totalSupply = 10 * 10 ** 26;
balances[msg.sender] = totalSupply;
name = "UFOToken";
symbol = "UFO";
decimals = 18;
}
}
找到和选择好Web3HpbTestApplication类,右击”Run as /Spring Boot App”
启动成功后,系统会出现类似如下提示:
12345678910111213
2019-01-09 10:49:18.538 HpbWeb3Test [main] INFO io.hpb.web3.Web3HpbTestApplication Caller+0 at org.springframework.boot.StartupInfoLogger.logStarting(StartupInfoLogger.java:50)
- Starting Web3HpbTestApplication on jason-hpbdeMBP with PID 46179 (/Users/hpb2017/git/web3-hpb-test/target/classes started by hpb2017 in /Users/hpb2017/git/web3-hpb-test)
2019-01-09 10:49:18.540 HpbWeb3Test [main] DEBUG io.hpb.web3.Web3HpbTestApplication Caller+0 at org.springframework.boot.StartupInfoLogger.logStarting(StartupInfoLogger.java:53)
- Running with Spring Boot v2.1.1.RELEASE, Spring v5.1.3.RELEASE
2019-01-09 10:49:18.542 HpbWeb3Test [main] INFO io.hpb.web3.Web3HpbTestApplication Caller+0 at org.springframework.boot.SpringApplication.logStartupProfileInfo(SpringApplication.java:675)
- No active profile set, falling back to default profiles: default
2019-01-09 10:49:20.818 HpbWeb3Test [main] INFO i.h.w.c.Web3AutoConfiguration Caller+0 at io.hpb.web3.configure.Web3AutoConfiguration.admin(Web3AutoConfiguration.java:51)
- Building admin service for endpoint: http://pub.node.hpb.io/
2019-01-09 10:49:21.406 HpbWeb3Test [main] INFO i.h.w.c.Web3AutoConfiguration Caller+0 at io.hpb.web3.configure.Web3AutoConfiguration.Web3(Web3AutoConfiguration.java:42)
- Building service for endpoint: http://pub.node.hpb.io/
2019-01-09 10:49:22.057 HpbWeb3Test [main] INFO io.hpb.web3.Web3HpbTestApplication Caller+0 at org.springframework.boot.StartupInfoLogger.logStarted(StartupInfoLogger.java:59)
- Started Web3HpbTestApplication in 3.943 seconds (JVM running for 5.429)
2.测试验证接口
Springboot的接口可以通过自带的swagger插件进行访问和测试。
打开本地访问地址:http://localhost:9988/HpbWeb3Test/swagger-ui.html#/
会显示如目前系统开放的测试接口,然后选择点击“hpb-web-3-controller”,接入该接口的具体方法测试界面。
点击“/getBalance”方法,点击“Try it out”开启编辑模式,输入你要查询余额的HPB地址;然后点击“Execute”开始执行。
系统会显示执行的结果,注意这里获取的余额显示的是科学计数法。
其他的接口可以依次根据接口的内容进行测试。
net_version
Returns the current network protocol version.
Parameters
none
Returns
String – The current network protocol version
Example
123456789
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"net_version","params":[],"id":67}'
// Result
{
"id":67,
"jsonrpc": "2.0",
"result": "59"
}
net_listening
Returns true if client is actively listening for network connections.
Parameters
none
Returns
Boolean – true when listening, otherwise false.
Example
123456789
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"net_listening","params":[],"id":67}'
// Result
{
"id":67,
"jsonrpc":"2.0",
"result":true
}
net_peerCount
Returns number of peers currenly connected to the client.
Parameters
none
Returns
QUANTITY – integer of the number of connected peers.
Example
123456789
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"net_peerCount","params":[],"id":74}'
// Result
{
"id":74,
"jsonrpc": "2.0",
"result": "0x2" // 2
}
hpb_protocolVersion
Returns the current hpb protocol version.
Parameters
none
Returns
String – The current hpb protocol version
Example
123456789
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_protocolVersion","params":[],"id":67}'
// Result
{
"id":67,
"jsonrpc": "2.0",
"result": "54"
}
hpb_syncing
Returns an object object with data about the sync status or FALSE.
Parameters
none
Returns
Object|Boolean, An object with sync status data or FALSE, when not syncing:
startingBlock: QUANTITY – The block at which the import started (will only be reset, after the sync reached his head)
currentBlock: QUANTITY – The current block, same as hpb_blockNumber
highestBlock: QUANTITY – The estimated highest block
Example
12345678910111213141516171819
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_isSyncing","params":[],"id":1}'
// Result
{
"id":1,
"jsonrpc": "2.0",
"result": {
startingBlock: '0x384',
currentBlock: '0x386',
highestBlock: '0x454'
}
}
// Or when not syncing
{
"id":1,
"jsonrpc": "2.0",
"result": false
}
hpb_coinbase
Returns the client coinbase address.
Parameters
none
Returns
DATA, 20 bytes – the current coinbase address.
Example
123456789
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_coinbase","params":[],"id":64}'
// Result
{
"id":64,
"jsonrpc": "2.0",
"result": "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
}
hpb_mining
Returns true if client is actively mining new blocks.
Parameters
none
Returns
Boolean – returns true of the client is mining, otherwise false.
Example
123456789
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_mining","params":[],"id":71}'
// Result
{
"id":71,
"jsonrpc": "2.0",
"result": true
}
hpb_gasPrice
Returns the current price per gas in wei.
Parameters
none
Returns
QUANTITY – integer of the current gas price in wei.
Example
123456789
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_gasPrice","params":[],"id":73}'
// Result
{
"id":73,
"jsonrpc": "2.0",
"result": "0x09184e72a000" // 10000000000000
}
hpb_accounts
Returns a list of addresses owned by client.
Parameters
none
Returns
Array of DATA, 20 Bytes – addresses owned by the client.
Example
123456789
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_accounts","params":[],"id":1}'
// Result
{
"id":1,
"jsonrpc": "2.0",
"result": ["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]
}
hpb_blockNumber
Returns the number of most recent block.
Parameters
none
Returns
QUANTITY – integer of the current block number the client is on.
Example
123456789
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_blockNumber","params":[],"id":83}'
// Result
{
"id":83,
"jsonrpc": "2.0",
"result": "0x4b7" // 1207
}
hpb_getBalance
Returns the balance of the account of given address.
Parameters
123456
DATA, 20 Bytes - address to check for balance.
QUANTITY|TAG - integer block number, or the string "latest", "earliest" or "pending"
params: [
'0x407d73d8a49eeb85d32cf465507dd71d507100c1',
'latest'
]
Returns
QUANTITY – integer of the current balance in wei.
hpb_getStorageAt
Returns the value from a storage position at a given address.
Parameters
12345678
DATA, 20 Bytes - address of the storage.
QUANTITY - integer of the position in the storage.
QUANTITY|TAG - integer block number, or the string "latest", "earliest" or "pending"
params: [
'0x407d73d8a49eeb85d32cf465507dd71d507100c1',
'0x0', // storage position at 0
'0x2' // state at block number 2
]
Returns
DATA – the value at this storage position.
Example
123456789
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_getStorageAt","params":["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "0x0", "0x2"],"id":1}'
// Result
{
"id":1,
"jsonrpc": "2.0",
"result": "0x03"
}
hpb_getTransactionCount
Returns the number of transactions sent from an address.
Parameters
123456
DATA, 20 Bytes - address.
QUANTITY|TAG - integer block number, or the string "latest", "earliest" or "pending"
params: [
'0x407d73d8a49eeb85d32cf465507dd71d507100c1',
'latest' // state at the latest block
]
Returns
QUANTITY – integer of the number of transactions send from this address.
Example
123456789
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_getTransactionCount","params":["0x407d73d8a49eeb85d32cf465507dd71d507100c1","latest"],"id":1}'
// Result
{
"id":1,
"jsonrpc": "2.0",
"result": "0x1" // 1
}
hpb_getBlockTransactionCountByHash
Returns the number of transactions in a block from a block matching the given block hash.
Parameters
1234
DATA, 32 Bytes - hash of a block
params: [
'0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238'
]
Returns
QUANTITY – integer of the number of transactions in this block.
Example
123456789
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_getBlockTransactionCountByHash","params":["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"],"id":1}'
// Result
{
"id":1,
"jsonrpc": "2.0",
"result": "0xb" // 11
}
hpb_getBlockTransactionCountByNumber
Returns the number of transactions in a block from a block matching the given block number.
Parameters
1234
QUANTITY|TAG - integer of a block number, or the string "earliest", "latest" or "pending".
params: [
'0xe8', // 232
]
Returns
QUANTITY – integer of the number of transactions in this block.
Example
123456789
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_getBlockTransactionCountByNumber","params":["0xe8"],"id":1}'
// Result
{
"id":1,
"jsonrpc": "2.0",
"result": "0xa" // 10
}
hpb_getUncleCountByBlockHash
Returns the number of uncles in a block from a block matching the given block hash.
Parameters
1234
DATA, 32 Bytes - hash of a block
params: [
'0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238'
]
Returns
QUANTITY – integer of the number of uncles in this block.
Example
123456789
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_getUncleCountByBlockHash","params":["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"],"id"Block:1}'
// Result
{
"id":1,
"jsonrpc": "2.0",
"result": "0x1" // 1
}
hpb_getUncleCountByBlockNumber
Returns the number of uncles in a block from a block matching the given block number.
Parameters
1234
QUANTITY - integer of a block number, or the string "latest", "earliest" or "pending"
params: [
'0xe8', // 232
]
Returns
QUANTITY – integer of the number of uncles in this block.
Example
123456789
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_getUncleCountByBlockNumber","params":["0xe8"],"id":1}'
// Result
{
"id":1,
"jsonrpc": "2.0",
"result": "0x1" // 1
}
hpb_getCode
Returns code at a given address.
Parameters
123456
DATA, 20 Bytes - address
QUANTITY|TAG - integer block number, or the string "latest", "earliest" or "pending"
params: [
'0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b',
'0x2' // 2
]
Returns
DATA – the code from the given address.
Example
123456789
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_getCode","params":["0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "0x2"],"id":1}'
// Result
{
"id":1,
"jsonrpc": "2.0",
"result": "0x600160008035811a818181146012578301005b601b6001356025565b8060005260206000f25b600060078202905091905056"
}
hpb_sendTransaction
Creates new message call transaction or a contract creation, if the data field contains code.
Parameters
12345678910111213141516
Object - The transaction object
from: DATA, 20 Bytes - The address the transaction is send from.
to: DATA, 20 Bytes - (optional when creating new contract) The address the transaction is directed to.
gas: QUANTITY - (optional, default: 90000) Integer of the gas provided for the transaction execution. It will return unused gas.
gasPrice: QUANTITY - (optional, default: To-Be-Determined) Integer of the gasPrice used for each paid gas
value: QUANTITY - (optional) Integer of the value send with this transaction
data: DATA - (optional) The compiled code of a contract
nonce: QUANTITY - (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.
params: [{
"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
"gas": "0x76c0", // 30400,
"gasPrice": "0x9184e72a000", // 10000000000000
"value": "0x9184e72a", // 2441406250
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
}]
Returns
DATA, 32 Bytes – the transaction hash, or the zero hash if the transaction is not yet available.
Use hpb_getTransactionReceipt to get the contract address, after the transaction was mined, when you created a contract.
Example
123456789
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_sendTransaction","params":[{see above}],"id":1}'
// Result
{
"id":1,
"jsonrpc": "2.0",
"result": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
}
hpb_sendRawTransaction
Creates new message call transaction or a contract creation for signed transactions.
Parameters
12345
Object - The transaction object
data: DATA, The signed transaction data.
params: [{
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
}]
Returns
DATA, 32 Bytes – the transaction hash, or the zero hash if the transaction is not yet available.
Use hpb_getTransactionReceipt to get the contract address, after the transaction was mined, when you created a contract.
Example
123456789
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_sendRawTransaction","params":[{see above}],"id":1}'
// Result
{
"id":1,
"jsonrpc": "2.0",
"result": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
}
hpb_call
Executes a new message call immediately without creating a transaction on the block chain.
Parameters
123456789
Object - The transaction call object
from: DATA, 20 Bytes - (optional) The address the transaction is send from.
to: DATA, 20 Bytes - The address the transaction is directed to.
gas: QUANTITY - (optional) Integer of the gas provided for the transaction execution. hpb_call consumes zero gas, but this parameter may be needed by some executions.
gasPrice: QUANTITY - (optional) Integer of the gasPrice used for each paid gas
value: QUANTITY - (optional) Integer of the value send with this transaction
data: DATA - (optional) The compiled code of a contract
QUANTITY|TAG - integer block number, or the string "latest", "earliest" or "pending"
Returns
DATA – the return value of executed contract.
Example
12345678910
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_call","params":[{see above}],"id":1}'
// Result
{
"id":1,
"jsonrpc": "2.0",
"result": "0x0"
}
hpb_estimateGas
Makes a call or transaction, which won’t be added to the blockchain and returns the used gas, which can be used for estimating the used gas.
Parameters
See hpb_call parameters, expect that all properties are optional.
hpb_getBlockByHash
Returns information about a block by hash.
Parameters
1234567
DATA, 32 Bytes - Hash of a block.
Boolean - If true it returns the full transaction objects, if false only the hashes of the transactions.
params: [
'0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
true
]
Returns
Object – A block object, or null when no block was found:
number: QUANTITY – the block number. null when its pending block.
hash: DATA, 32 Bytes – hash of the block. null when its pending block.
parentHash: DATA, 32 Bytes – hash of the parent block.
nonce: DATA, 8 Bytes – hash of the generated proof-of-work. null when its pending block.
sha3Uncles: DATA, 32 Bytes – SHA3 of the uncles data in the block.
logsBloom: DATA, 256 Bytes – the bloom filter for the logs of the block. null when its pending block.
transactionsRoot: DATA, 32 Bytes – the root of the transaction trie of the block.
stateRoot: DATA, 32 Bytes – the root of the final state trie of the block.
receiptsRoot: DATA, 32 Bytes – the root of the receipts trie of the block.
miner: DATA, 20 Bytes – the address of the beneficiary to whom the mining rewards were given.
difficulty: QUANTITY – integer of the difficulty for this block.
totalDifficulty: QUANTITY – integer of the total difficulty of the chain until this block.
extraData: DATA – the “extra data” field of this block.
size: QUANTITY – integer the size of this block in bytes.
gasLimit: QUANTITY – the maximum gas allowed in this block.
gasUsed: QUANTITY – the total used gas by all transactions in this block.
timestamp: QUANTITY – the unix timestamp for when the block was collated.
transactions: Array – Array of transaction objects, or 32 Bytes transaction hashes depending on the last given parameter.
uncles: Array – Array of uncle hashes.
Example
hpb_getBlockByNumber
Returns information about a block by block number.
Parameters
1234567
QUANTITY|TAG - integer of a block number, or the string "earliest", "latest" or "pending"
Boolean - If true it returns the full transaction objects, if false only the hashes of the transactions.
params: [
'0x1b4', // 436
true
]
Returns
See hpb_getBlockByHash
Example
1234
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_getBlockByNumber","params":["0x1b4", true],"id":1}'
Result see hpb_getBlockByHash
hpb_getTransactionByHash
Returns the information about a transaction requested by transaction hash.
Parameters
12345
DATA, 32 Bytes - hash of a transaction
params: [
"0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"
]
Returns
Object – A transaction object, or null when no transaction was found:
hash: DATA, 32 Bytes – hash of the transaction.
nonce: QUANTITY – the number of transactions made by the sender prior to this one.
blockHash: DATA, 32 Bytes – hash of the block where this transaction was in. null when its pending.
blockNumber: QUANTITY – block number where this transaction was in. null when its pending.
transactionIndex: QUANTITY – integer of the transactions index position in the block. null when its pending.
from: DATA, 20 Bytes – address of the sender.
to: DATA, 20 Bytes – address of the receiver. null when its a contract creation transaction.
value: QUANTITY – value transferred in Wei.
gasPrice: QUANTITY – gas price provided by the sender in Wei.
gas: QUANTITY – gas provided by the sender.
input: DATA – the data send along with the transaction.
Example
hpb_getTransactionByBlockHashAndIndex
Returns information about a transaction by block hash and transaction index position.
Parameters
1234567
DATA, 32 Bytes - hash of a block.
QUANTITY - integer of the transaction index position.
params: [
'0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
'0x0' // 0
]
Returns
See hpb_getBlockByHash
Example
1234
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_getTransactionByBlockHashAndIndex","params":[0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b, "0x0"],"id":1}'
Result see hpb_getTransactionByHash
hpb_getTransactionByBlockNumberAndIndex
Returns information about a transaction by block number and transaction index position.
Parameters
12345678
QUANTITY|TAG - a block number, or the string "earliest", "latest" or "pending".
QUANTITY - the transaction index position.
params: [
'0x29c', // 668
'0x0' // 0
]
Returns
See hpb_getBlockByHash
Example
1234
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_getTransactionByBlockNumberAndIndex","params":["0x29c", "0x0"],"id":1}'
Result see hpb_getTransactionByHash
hpb_getTransactionReceipt
Returns the receipt of a transaction by transaction hash.
Note That the receipt is not available for pending transactions.
Parameters
12345
DATA, 32 Bytes - hash of a transaction
params: [
'0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238'
]
Returns
Object – A transaction receipt object, or null when no receipt was found:
transactionHash: DATA, 32 Bytes – hash of the transaction.
transactionIndex: QUANTITY – integer of the transactions index position in the block.
blockHash: DATA, 32 Bytes – hash of the block where this transaction was in.
blockNumber: QUANTITY – block number where this transaction was in.
cumulativeGasUsed: QUANTITY – The total amount of gas used when this transaction was executed in the block.
gasUsed: QUANTITY – The amount of gas used by this specific transaction alone.
contractAddress: DATA, 20 Bytes – The contract address created, if the transaction was a contract creation, otherwise null.
logs: Array – Array of log objects, which this transaction generated.
Example
123456789101112131415161718192021
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_getTransactionReceipt","params":["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"],"id":1}'
// Result
{
"id":1,
"jsonrpc":"2.0",
"result": {
transactionHash: '0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238',
transactionIndex: '0x1', // 1
blockNumber: '0xb', // 11
blockHash: '0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b',
cumulativeGasUsed: '0x33bc', // 13244
gasUsed: '0x4dc', // 1244
contractAddress: '0xb60e8dd61c5d32be8058bb8eb970870f07233155' // or null, if none was created
logs: [{
// logs as returned by getFilterLogs, etc.
}, ...]
}
}
hpb_getUncleByBlockHashAndIndex
Returns information about a uncle of a block by hash and uncle index position.
Parameters
1234567
DATA, 32 Bytes - hash a block.
QUANTITY - the uncle's index position.
params: [
'0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b',
'0x0' // 0
]
Returns
See hpb_getBlockByHash
Example
123456
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_getUncleByBlockHashAndIndex","params":["0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "0x0"],"id":1}'
Result see hpb_getBlockByHash
Note: An uncle doesn't contain individual transactions.
hpb_getUncleByBlockNumberAndIndex
Returns information about a uncle of a block by number and uncle index position.
Parameters
1234567
QUANTITY|TAG - a block number, or the string "earliest", "latest" or "pending".
QUANTITY - the uncle's index position.
params: [
'0x29c', // 668
'0x0' // 0
]
Returns
See hpb_getBlockByHash
Note: An uncle doesn’t contain individual transactions.
Example
1234
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_getUncleByBlockNumberAndIndex","params":["0x29c", "0x0"],"id":1}'
Result see hpb_getBlockByHash
hpb_newFilter
Creates a filter object, based on filter options, to notify when the state changes (logs). To check if the state has changed, call hpb_getFilterChanges.
Parameters
123456789101112
Object - The filter options:
fromBlock: QUANTITY|TAG - (optional, default: "latest") Integer block number, or "latest" for the last mined block or "pending", "earliest" for not yet mined transactions.
toBlock: QUANTITY|TAG - (optional, default: "latest") Integer block number, or "latest" for the last mined block or "pending", "earliest" for not yet mined transactions.
address: DATA|Array, 20 Bytes - (optional) Contract address or a list of addresses from which logs should originate.
topics: Array of DATA, - (optional) Array of 32 Bytes DATA topics.
params: [{
"fromBlock": "0x1",
"toBlock": "0x2",
"address": "0x8888f1f195afa192cfee860698584c030f4c9db1",
"topics": ["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b"]
}]
Returns
QUANTITY – A filter id.
Example
12345678910
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_newFilter","params":[{"topics":["0x12341234"]}],"id":73}'
// Result
{
"id":1,
"jsonrpc": "2.0",
"result": "0x1" // 1
}
hpb_newBlockFilter
Creates a filter in the node, to notify when a new block arrives. To check if the state has changed, call hpb_getFilterChanges.
Parameters
None
Returns
QUANTITY – A filter id.
Example
12345678910
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_newBlockFilter","params":[],"id":73}'
// Result
{
"id":1,
"jsonrpc": "2.0",
"result": "0x1" // 1
}
hpb_newPendingTransactionFilter
Creates a filter in the node, to notify when new pending transactions arrive. To check if the state has changed, call hpb_getFilterChanges.
Parameters
None
Returns
QUANTITY – A filter id.
Example
12345678910
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_newPendingTransactionFilter","params":[],"id":73}'
// Result
{
"id":1,
"jsonrpc": "2.0",
"result": "0x1" // 1
}
hpb_uninstallFilter
Uninstalls a filter with given id. Should always be called when watch is no longer needed. Additonally Filters timeout when they aren’t requested with hpb_getFilterChanges for a period of time.
Parameters
12345
QUANTITY - The filter id.
params: [
"0xb" // 11
]
Returns
Boolean – true if the filter was successfully uninstalled, otherwise false.
Example
12345678910
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_uninstallFilter","params":["0xb"],"id":73}'
// Result
{
"id":1,
"jsonrpc": "2.0",
"result": true
}
hpb_getFilterChanges
Polling method for a filter, which returns an array of logs which occurred since last poll.
Returns
Array – Array of log objects, or an empty array if nothing has changed since last poll.
For filters created with hpb_newBlockFilter the return are block hashes (DATA, 32 Bytes), e.g. [“0x3454645634534…”].
For filters created with hpb_newPendingTransactionFilter the return are transaction hashes (DATA, 32 Bytes), e.g. [“0x6345343454645…”].
For filters created with hpb_newFilter logs are objects with following params:
type: TAG – pending when the log is pending. mined if log is already mined.
logIndex: QUANTITY – integer of the log index position in the block. null when its pending log.
transactionIndex: QUANTITY – integer of the transactions index position log was created from. null when its pending log.
transactionHash: DATA, 32 Bytes – hash of the transactions this log was created from. null when its pending log.
blockHash: DATA, 32 Bytes – hash of the block where this log was in. null when its pending. null when its pending log.
blockNumber: QUANTITY – the block number where this log was in. null when its pending. null when its pending log.
address: DATA, 20 Bytes – address from which this log originated.
data: DATA – contains one or more 32 Bytes non-indexed arguments of the log.
topics: Array of DATA – Array of 0 to 4 32 Bytes DATA of indexed log arguments. (In solidity: The first topic is the hash of the signature of the event (e.g. Deposit(address,bytes32,uint256)), except you declared the event with the anonymous specifier.)
Example
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_getFilterLogs","params":["0x16"],"id":74}'
Result see hpb_getFilterChanges
hpb_getLogs
Returns an array of all logs matching a given filter object.
Parameters
12345
Object - the filter object, see hpb_newFilter parameters.
params: [{
"topics": ["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b"]
}]
Returns
See hpb_getFilterChanges
Example
1234
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"hpb_getLogs","params":[{"topics":["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b"]}],"id":74}'
Result see hpb_getFilterChanges
personal_newAccount
Returns a new account public address
Parameters
12345
DATA
params: [{
'12345678'
}]
Returns
DATA – address:
Example
123456789101112
// Request
curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"personal_newAccount","params":['12345678'],"id":83}'
// Result
{
"id":1,
"jsonrpc":"2.0",
"result": [
"0x5670b4f2810115fd7cf198433345a7e767de82bf"
]
}
var Web3ForHpb = require('web3_hpb');
var web3Hpb = new Web3ForHpb();
web3Hpb.setProvider(new web3Hpb.providers.HttpProvider("http://localhost:8545"));
web3Hpb.hpb.contract(abi).new({
data: '0x' + bytecode,
from: "",
gas: 1000000
}, (err, res) => {
if (err) {
console.log(err);
return;
}
console.log(res.transactionHash);
// If we have an address property, the contract was deployed
if (res.address) {
console.log('Contract address: ' + res.address);
}
});
var hpbTestContract = web3Hpb.hpb.contract(abi).at(contractAddress);
console.log(hpbTestContract.getContractAddr.call());
root@dell-PowerEdge-R730:/home/hpb# vi /etc/profileif[-d/etc/profile.d];thenforiin/etc/profile.d/*.sh;doif[-r$i];then.$ifidoneunsetifiumask027TMOUT=180:wq(先按下”ESC”键,再输入”:wq”就可以保存文件并退出)
root@dell-PowerEdge-R730:/home/hpb# vi /etc/bash.bashrcif[-d/etc/profile.d];thenforiin/etc/profile.d/*.sh;doif[-r$i];then.$ifidoneunsetifiumask027TMOUT=180:wq(先按下”ESC”键,再输入”:wq”就可以保存文件并退出)
root@dell-PowerEdge-R730:/home/hpb# vi /etc/ssh/sshd_config# Authentication:LoginGraceTime120PermitRootLoginprohibit-passwordStrictModesyes:wq(先按下”ESC”键,再输入”:wq”就可以保存文件并退出)
3.19 运行的服务
用户需检查运行结果中显示的服务,并尽量关闭不必要的服务。
提示:关闭服务的命令为” chkconfig –level \$level<服务名> ”
3.20 Core dupm状态
配置修改步骤
编号
步骤
说明
1
切换root(已切换的用户可跳过)
命令:” su root“ 提示:用户需根据提示输入root账户密码 |
2
修改limits文件
命令:”vi/etc/security/limits.conf“ 在文档末尾”End of file”前输入: ”* soft core 0 * hard core 0” |
root@dell-PowerEdge-R730:/home/hpb##ftp hard nproc 0#ftp - chroot /ftp#@student - maxlogins 4*softcore0*hardcore0# End of file:wq(先按下”ESC”键,再输入”:wq”就可以保存文件并退出)
root@dell-PowerEdge-R730:/home/hpb# vi /etc/rsyslog.conf ## Include all config files in /etc/rsyslog.d/#$IncludeConfig/etc/rsyslog.d/*.conf*.err;kern.debug;daemon.notice/var/adm/messages:wq(先按下”ESC”键,再输入”:wq”就可以保存文件并退出)