Split value into wholeCoin and Satoshis when serialized & recombine on deserialization

This commit is contained in:
Sky Young 2018-05-10 13:54:01 -07:00
parent 5ea942b54b
commit 242fb759e6

View File

@ -2150,11 +2150,17 @@ ChainState.prototype.commit = function commit(hash) {
};
ChainState.prototype.toRaw = function toRaw() {
const bw = new StaticWriter(56);
const bw = new StaticWriter(64);
bw.writeHash(this.tip);
bw.writeU64(this.tx);
bw.writeU64(this.coin);
bw.writeU64(this.value);
var wholeCoinValue = Math.floor(this.value / Math.pow(10,8))
var satoshiCoinValue = this.value - (wholeCoinValue * Math.pow(10,8));
bw.writeU64BE(wholeCoinValue);
bw.writeU64BE(satoshiCoinValue);
return bw.render();
};
@ -2164,7 +2170,12 @@ ChainState.fromRaw = function fromRaw(data) {
state.tip = br.readHash('hex');
state.tx = br.readU64();
state.coin = br.readU64();
state.value = br.readU64();
var wholeCoinValue = br.readU64BE();
var satoshiCoinValue = br.readU64BE();
state.value = (wholeCoinValue * Math.pow(10,8)) + satoshiCoinValue;
return state;
};