Split value into wholeCoin and Satoshis when serialized & recombine on deserialization
This commit is contained in:
parent
5ea942b54b
commit
242fb759e6
@ -2150,11 +2150,17 @@ ChainState.prototype.commit = function commit(hash) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ChainState.prototype.toRaw = function toRaw() {
|
ChainState.prototype.toRaw = function toRaw() {
|
||||||
const bw = new StaticWriter(56);
|
const bw = new StaticWriter(64);
|
||||||
bw.writeHash(this.tip);
|
bw.writeHash(this.tip);
|
||||||
bw.writeU64(this.tx);
|
bw.writeU64(this.tx);
|
||||||
bw.writeU64(this.coin);
|
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();
|
return bw.render();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2164,7 +2170,12 @@ ChainState.fromRaw = function fromRaw(data) {
|
|||||||
state.tip = br.readHash('hex');
|
state.tip = br.readHash('hex');
|
||||||
state.tx = br.readU64();
|
state.tx = br.readU64();
|
||||||
state.coin = 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;
|
return state;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user