Feel free to close if this is not the place for support.
I am stuck at the POC stage of generating a valid send block my local node keep spitting out Block is invalid
, I feel like I am missing something surrounding core concepts here, but I hit a wall so I figured I would reach out.
Environment:
Node Version - V21.0DB12
NanoCurrency Version - 2.4.0
Execution Environment - Firefox 76.0.1 (browserify)
As far as I can tell the core issue is that I seem to be generating the work incorrectly:
My javascript generated work - 000000000248a56b
The nodes generated work (rpc wallet actions) - aaa4e12ae1b25720
I thought this might be because it is a genesis account and the frontier is not valid for work generation, so I bounced the funds about a bit and used an opened and transacted upon account, but seems to still generate invalid work. (same thing many trailing zeros in the work)
Full info
POC code: ( this is a local genesis account all the data is ephemeral)
var nanocurrency = require('nanocurrency');
var BigNumber = require('bignumber.js');
var rpcurl = 'http://192.168.10.13:7076';
async function rpcall(body) {
var Init = { method:'POST',body: JSON.stringify(body)};
var res = await fetch(rpcurl,Init);
var data = await res.json();
return data;
}
var sender = 'nano_1rxzhkj8jhodn338k65uesk8jk8zxsmyidbw4gtaus984pxc63xbatbfm8on';
var destination = 'nano_34qdxa5u1gb8ciwn7kct93wmza4wgwrx6a6u5qop5i9p3j3rkjnf61q5uxax';
var senderprivate = '0C9A87A49A2DD56FE37EF6283A30D32D945BC2B7F2CF675C639C1350AC468204';
var amount = '10000';
var info = {};
info['action'] = 'account_info';
info['representative'] = 'true';
info['account'] = sender;
var res = await rpcall(info);
console.log(res);
console.log('Calculating pow for ' + res.frontier + ' this may take some time')
var pow = await nanocurrency.computeWork(res.frontier);
var balance = new BigNumber(res.balance).minus(new BigNumber(amount)).toFixed();
var block = nanocurrency.createBlock(senderprivate, {
work: pow,
previous: res.frontier,
representative: res.representative,
balance: balance,
link: destination
});
console.log(block);
var send = {};
send['action'] = 'process';
send['json_block'] = 'true';
send['subtype'] = 'send';
send['block'] = block;
var sendres = await rpcall(send);
console.log(sendres);
Account Info:
{
frontier: "4C49618F2B4B5DA9120847D92B261C68DFEEBD8F6BADB93619D00E1B5E2902FD",
open_block: "4C49618F2B4B5DA9120847D92B261C68DFEEBD8F6BADB93619D00E1B5E2902FD",
representative_block: "4C49618F2B4B5DA9120847D92B261C68DFEEBD8F6BADB93619D00E1B5E2902FD",
balance: "340282366920938463463374607431768211455",
modified_timestamp: "1589476181",
block_count: "1",
account_version: "0",
confirmation_height: "1",
confirmation_height_frontier: "4C49618F2B4B5DA9120847D92B261C68DFEEBD8F6BADB93619D00E1B5E2902FD",
representative: "nano_1rxzhkj8jhodn338k65uesk8jk8zxsmyidbw4gtaus984pxc63xbatbfm8on"
}
Generated Block:
{
account: "xrb_1rxzhkj8jhodn338k65uesk8jk8zxsmyidbw4gtaus984pxc63xbatbfm8on",
balance: "340282366920938463463374607431768201455",
link: "8AEBEA07B03926543942C95A38793FA05C7731D2209B1DEB61C0F60C4389468D",
link_as_account: "nano_34qdxa5u1gb8ciwn7kct93wmza4wgwrx6a6u5qop5i9p3j3rkjnf61q5uxax",
previous: "4C49618F2B4B5DA9120847D92B261C68DFEEBD8F6BADB93619D00E1B5E2902FD",
representative: "nano_1rxzhkj8jhodn338k65uesk8jk8zxsmyidbw4gtaus984pxc63xbatbfm8on",
signature: "DA8B7A1BD949D743EE767D477F014116F2B7ABEAF75A6E5335C5F0D6FC12A81839ABF88EB81702304A83204AB4EA80B7026345BF0D1B5F299A04B037D8CE1A02",
type: "state",
work: "000000000248a56b"
}
The Block that an RPC send command generates:
{
"type": "state",
"account": "nano_1rxzhkj8jhodn338k65uesk8jk8zxsmyidbw4gtaus984pxc63xbatbfm8on",
"previous": "4C49618F2B4B5DA9120847D92B261C68DFEEBD8F6BADB93619D00E1B5E2902FD",
"representative": "nano_1rxzhkj8jhodn338k65uesk8jk8zxsmyidbw4gtaus984pxc63xbatbfm8on",
"balance": "340282366920938463463374607431768201455",
"link": "8AEBEA07B03926543942C95A38793FA05C7731D2209B1DEB61C0F60C4389468D",
"link_as_account": "nano_34qdxa5u1gb8ciwn7kct93wmza4wgwrx6a6u5qop5i9p3j3rkjnf61q5uxax",
"signature": "2300B3B178CEE95CE5E839037418E53FCFAEBD48E1FE06C2ED40174E8A121A8DD2660BE31D60089739328A589844915FC7F04C1EA348409587E8D3287A04940C",
"work": "aaa4e12ae1b25720"
}