Skip to content

Instantly share code, notes, and snippets.

@planethouki
Last active February 10, 2019 06:10
Show Gist options
  • Save planethouki/f1ad71bd7e809a0c61347cd04c78a24a to your computer and use it in GitHub Desktop.
Save planethouki/f1ad71bd7e809a0c61347cd04c78a24a to your computer and use it in GitHub Desktop.
nem catapult バイトレベルで理解する その2 TransferTransaction ref: https://qiita.com/planethouki/items/025d44f2ebe6cfcb4b1f
new Mosaic(new MosaicId('nem:xem'), UInt64.fromUint(10000000))
$ node
> number = 0x0001F8645223984F
1378064463
> number & 0xFFFFFFFF
1378064463
> (number & 0xFFFFFFFF) >>> 0
1378064463
> (1378064463).toString(16).toUpperCase()
'5223984F'
$ node
> number = 0x0001F8645223984F
1378064463
> number / 0x100000000
129124.32085563592
> (number / 0x100000000) >>> 0
129124
> (129124).toString(16).toUpperCase()
'1F864'
> nem2Sdk.UInt64.fromUint(2729735958921713743);
UInt64 { lower: 1378064384, higher: 635566180 }
{ lower: 0x52239800, higher: 0x25E1F864 }
/**
* Transfer transaction schema
* @const {module:schema/Schema}
*/
const schema = new Schema([
uint('size'),
array('signature'),
array('signer'),
ushort('version'),
ushort('type'),
array('fee', TypeSize.INT),
array('deadline', TypeSize.INT),
array('recipient'),
ushort('messageSize'),
ubyte('numMosaics'),
table('message', [
ubyte('type'),
array('payload')
]),
tableArray('mosaics', [
array('id', TypeSize.INT),
array('amount', TypeSize.INT)
])
]);
/**
* Converts a numeric unsigned integer into a uint64.
* @param {number} number The unsigned integer.
* @returns {module:coders/uint64~uint64} The uint64 representation of the input.
*/
fromUint: number => {
const value = [(number & 0xFFFFFFFF) >>> 0, (number / 0x100000000) >>> 0];
//if (0x00200000 <= value[1] || 0 > number || 0 !== (number % 1))
// throw Error(`number cannot be converted to uint '${number}'`);
return value;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment