日志记录
有四个级别的日志记录:
info,信息。
warn,警告。
error,错误。
debug,调试。
默认情况下,info、warn和error条目将发送到控制台console,不会记录debug。
交易信息并不会直接从区块链种查询,通过eth.filter实时监听区块上的日志,将所有的交易数据存储到本地数据库中,需要查询的时候直接从本地数据库中查询
4.帮助我们通过filter过滤出历史交易数据.
下面的方法具体实现我们开始讲的通过filter办法,从链上扒出历史交易数据的办法。
//以下是web3.js代码:
var depositEvent = cryptoExContract.Deposit({_sender: userAddress});
depositEvent.watch(function(err, result) {
if (err) {
console.log(err)
return;
}
else{
// append details of result.args to UI
//将这笔交易写入客户端资料库中,方便以后查询历史交易数据。
}
})
//通过增加fromBlock参数指定关注的区块范围,来查询所有的交易数据。(获取链上存储的历史交易数据,我们用扒链的办法来获取,因为eth目前没有提供获取历史数据的API。)
var depositEventAll = cryptoExContract.Deposit({_sender: userAddress}, {fromBlock: 0, toBlock: ‘latest’});
depositEventAll.watch(function(err, result) {
if (err) {
console.log(err)
return;
}
else{
// append details of result.args to UI
//如果不想再被通知可以调用:
//depositEventAll.stopWatching();
}
})
启动节点
geth --rpc --nodiscover --datadir “./nodedata0” --port 30303 --rpcapi “db,eth,net,web3” --rpccorsdomain “*” --networkid 1001 --ipcdisable console 2>>geth.log
–datadir 区块链数据存储目录
console 打开一个可交互的javascript环境
2>>geth.log 把geth中的log信息导入geth.log,也可以不加这个,把信息直接输出在console里,这样直观
更多参数:https://github.com/ethereum/go-ethereum/wiki/Command-Line-Options
http://www.yaozihao.cn/2017/07/07/geth%E5%91%BD%E4%BB%A4%E9%80%89%E9%A1%B9%E4%BB%8B%E7%BB%8D/
根据显示信息去找到那个geth.log文件