Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
dataAccessOptions: {
connectOnInit: true,
connectionString: DB_CONNECTION_STRING,
collectionNames: {
blocks: 'b_neo_t_blocks',
transactions: 'b_neo_t_transactions',
addresses: 'b_neo_t_addresses'
}
}
}
}
const neo = new Neo(options)
// Instantiate RPC via NeonJS
const url = 'http://seed2.neo.org:20332'
const rpc = Neon.rpc.default.create.rpcClient(url)
// Keep looking and cherrypick blocks, and examine them
setInterval(async () => {
// Fetch local node height
const localBlockHeight = await neo.storage.getBlockCount()
// Generate random number in between
const randomHeight = parseInt(Math.random() * localBlockHeight)
// logger.info('localBlockHeight:', localBlockHeight, 'randomHeight:', randomHeight)
// Fetch block from local node
const localBlock = await neo.storage.getBlock(randomHeight)
// logger.info('localBlock:', localBlock.hash)
// Fetch block from remote node via NodeJs
const remoteBlock = await rpc.getBlock(randomHeight)
return module.exports.getRPCEndpoint().then(rpcEndpoint => {
return neon.rpc.Query.invokeScript(vmScript)
.execute(rpcEndpoint)
.then((res) => {
if (res.result.state === 'HALT, BREAK') {
//Execute the transaction
module.exports.executeTransaction(account, invoke, gasCost, intents).then(res => {
if (res !== undefined)
callback(res)
else
return
})
} else {
console.log('Error:', res)
}
})
})
}
const EventEmitter = require('events')
const axios = require('axios')
const Neon = require('@cityofzion/neon-js')
const Query = Neon.rpc.Query
const Logger = require('../common/logger')
/**
* @class Rpc
* @param {string} domain
* @param {string} port
* @param {Object} options
* @param {Object} options.loggerOptions
*/
class Rpc extends EventEmitter {
/**
* @fires Rpc#constructor:complete
*/
constructor (domain, port, options) {
super()
initNeonRpc () {
this.neonRpc = Neon.rpc.default.create.rpcClient(this.getRpcUrl())
}
return __awaiter(this, void 0, void 0, function* () {
rpc_validator_1.RpcValidator.validateUrl(url);
rpc_validator_1.RpcValidator.validateMethod(method);
rpc_validator_1.RpcValidator.validateId(id);
const q = new neon_js_1.rpc.Query({ method, params, id });
return yield q.execute(url, requestConfig);
});
}
return module.exports.getRPCEndpoint().then(rpcEndpoint => {
return neon.rpc.queryRPC(rpcEndpoint, {
method: method,
params: params,
id: id
}).then(res => {
return res
}).catch(err => {
return err
})
})
},