diff --git a/lib/blockchain/chaindb.js b/lib/blockchain/chaindb.js index 13117903..322af916 100644 --- a/lib/blockchain/chaindb.js +++ b/lib/blockchain/chaindb.js @@ -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; };