Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.map(data => {
const url = buildNodeUrl(data)
const client = new rpc.RPCClient(url)
// eslint-disable-next-line
data.client = client
return data
})
.then(transaction => {
const client = new rpc.RPCClient(rpcNodeUrl);
return client.sendRawTransaction(transaction.serialize(true));
})
.then(res => {
async function getAssetBalances(endpoint, address) {
const client = new rpc.RPCClient(endpoint);
const { balances } = await client.getAccountState(address);
const neoBalance = get(find(balances, { asset: `0x${NEO}` }), 'value', '0');
const gasBalance = get(find(balances, { asset: `0x${GAS}` }), 'value', '0');
return {
[NEO]: { ...ASSETS[NEO], scriptHash: NEO, balance: neoBalance },
[GAS]: { ...ASSETS[GAS], scriptHash: GAS, balance: gasBalance }
};
}
handleBroadcast = async (rawTransaction: string) => {
this.setState({ loading: true })
const { net } = this.props
let url = await getNode(net)
if (isEmpty(url)) {
url = await getRPCEndpoint(net)
}
const RPC = new rpc.RPCClient(url)
const response = await RPC.sendRawTransaction(rawTransaction).catch(e => {
this.props.showErrorNotification({
message: `There was an issue broadcasting the transaction to the network... ${
e.message
}`,
})
this.setState({ loading: false })
})
if (response) {
this.props.showSuccessNotification({
message:
'Transaction pending! Wallet balances will automatically update when the blockchain has processed it.',
})
this.setState({ loading: false })
this.props.hideModal()
}
const goodNodes = nodes.filter((n) => !isUnreliableNode(n.url, blacklist));
if (goodNodes.length === 0) {
throw new Error('No eligible nodes found!');
}
const heightThreshold = goodNodes[0].height - 1;
const highestNodes = goodNodes.filter((n) => n.height >= heightThreshold);
const urls = highestNodes.map((n) => n.url);
if (urls.length === 0) {
throw new Error('No eligible nodes found!');
}
if (urls.includes(cachedRPC)) {
return new rpc.RPCClient(cachedRPC).ping().then((num) => {
if (num <= settings.timeout.ping) return cachedRPC;
cachedRPC = null;
return getRPCEndpoint(net);
});
}
const clients = urls.map((u) => new rpc.RPCClient(u));
const fastestUrl = await raceToSuccess(clients.map((c) => c.ping().then(() => c.net)));
cachedRPC = fastestUrl;
return fastestUrl;
}
({ networkId, address }: Props = {}) => async (state: Object) => {
const net = getNetworkById(networkId)
const endpoint = await api.getRPCEndpointFrom({ net }, api.neoscan)
const client = new rpc.RPCClient(endpoint)
const validators = await client.getValidators()
const accountState = await client.getAccountState(address)
return {
validators,
votes: accountState.votes,
}
},
)
async function resolveNameService(url) {
const { host, pathname } = url;
const endpoint = await getRPCEndpoint(NOS_TESTNET);
const client = new rpc.RPCClient(endpoint);
const storageKey = u.str2hexstring(`${host}.target`);
const response = await client.getStorage(NS_SCRIPT_HASH, storageKey);
if (!response) {
throw new Error('Not found.');
}
const target = u.hexstring2str(response);
return `${target}${pathname}`;
}
new Promise(resolve => {
const client = new rpc.RPCClient(url)
client.ping().then(latency => {
if (client.lastSeenHeight !== 0) {
resolve({
url,
blockCount: client.lastSeenHeight,
latency,
})
}
})
})
const clients = urls.map((u) => new rpc.RPCClient(u));
export default createActions(ID, ({ net }) => async () => {
const endpoint = await getRPCEndpoint(net);
const client = new rpc.RPCClient(endpoint);
const height = await client.getBlockCount();
return client.getBlock(height - 1);
});