添加pullBlockData
This commit is contained in:
parent
c9813430d9
commit
470a785c14
@ -148,6 +148,10 @@ class BlockChain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getBlockData(blockNumber) {
|
||||||
|
return await this.web3.eth.getBlock(blockNumber);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = BlockChain;
|
module.exports = BlockChain;
|
||||||
|
@ -67,6 +67,10 @@ class BlockChain extends BaseService {
|
|||||||
return await this.#bc[contractName + 'Instance'].methods.ownerOf(tokenId).call();
|
return await this.#bc[contractName + 'Instance'].methods.ownerOf(tokenId).call();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getBlockData(blockNumber) {
|
||||||
|
return await this.#bc.getBlockData(blockNumber);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = BlockChain;
|
module.exports = BlockChain;
|
||||||
|
@ -70,7 +70,11 @@ class PullBcEvent extends BaseService {
|
|||||||
async (event) => {
|
async (event) => {
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
await this.saveToDb(event);
|
const blockData = null;
|
||||||
|
if (this.needPullBlockData()) {
|
||||||
|
blockData = await this.getBlockData(event['blockNumber']);
|
||||||
|
}
|
||||||
|
await this.saveToDb(event, blockData);
|
||||||
return;
|
return;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
utils.safeDumpErrStack(err);
|
utils.safeDumpErrStack(err);
|
||||||
@ -81,6 +85,23 @@ class PullBcEvent extends BaseService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getBlockData(blockNumber) {
|
||||||
|
const logHead = this.genLogHead(' getBlockData: ');
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
const blockData = await this.bc.getBlockData(blockNumber);
|
||||||
|
console.log(blockData);
|
||||||
|
return blockData;
|
||||||
|
return blockData;
|
||||||
|
} catch (err) {
|
||||||
|
utils.safeDumpErrStack(err);
|
||||||
|
log.error(logHead + err);
|
||||||
|
await utils.sleep(2000 + utils.randRange(10, 2000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
async getFromBlock() {
|
async getFromBlock() {
|
||||||
const logHead = this.genLogHead(' getFromBlock: ');
|
const logHead = this.genLogHead(' getFromBlock: ');
|
||||||
const firstBlockNumber = this.getInitBlock();
|
const firstBlockNumber = this.getInitBlock();
|
||||||
@ -166,7 +187,7 @@ class PullBcEvent extends BaseService {
|
|||||||
this.lastBlockNumber = blockNumber;
|
this.lastBlockNumber = blockNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
async saveToDb(event) {
|
async saveToDb(event, blockData) {
|
||||||
const logHead = this.genLogHead(' event_process.saveToDb: ');
|
const logHead = this.genLogHead(' event_process.saveToDb: ');
|
||||||
while (true) {
|
while (true) {
|
||||||
const nowTime = utils.getUtcTime();
|
const nowTime = utils.getUtcTime();
|
||||||
@ -198,6 +219,7 @@ class PullBcEvent extends BaseService {
|
|||||||
['block_number', event['blockNumber']],
|
['block_number', event['blockNumber']],
|
||||||
['raw_data', rawData.length < 1024 * 1024 ? rawData : ''],
|
['raw_data', rawData.length < 1024 * 1024 ? rawData : ''],
|
||||||
['return_values', utils.jsonEncode(returnValues)],
|
['return_values', utils.jsonEncode(returnValues)],
|
||||||
|
['block_data', utils.jsonEncode(blockData)],
|
||||||
['createtime', utils.getUtcTime()],
|
['createtime', utils.getUtcTime()],
|
||||||
['modifytime', utils.getUtcTime()],
|
['modifytime', utils.getUtcTime()],
|
||||||
]
|
]
|
||||||
@ -233,6 +255,13 @@ class PullBcEvent extends BaseService {
|
|||||||
return this.eventConf['contract_name'];
|
return this.eventConf['contract_name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
needPullBlockData() {
|
||||||
|
if (utils.hasKey(this.eventConf, 'pull_block_data')) {
|
||||||
|
return this.eventConf['pull_block_data'];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
genLogHead(msg) {
|
genLogHead(msg) {
|
||||||
const logHead = this.getNetId() + ' ' + this.getContractName() + '.' +
|
const logHead = this.getNetId() + ' ' + this.getContractName() + '.' +
|
||||||
this.getEventName() + ' pull_bcevent ' + msg;
|
this.getEventName() + ' pull_bcevent ' + msg;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user