Skip to content

Commit 7bfab71

Browse files
authored
Merge pull request #155 from kilpatty/txmeta-json-fix
various: convert buffer to string for JSON
2 parents ca78565 + 9d33191 commit 7bfab71

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

lib/node/rpc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ class RPC extends RPCBase {
709709
if (!hash)
710710
throw new RPCError(errs.MISC_ERROR, 'Not found.');
711711

712-
return hash;
712+
return hash.toString('hex');
713713
}
714714

715715
async getBlockHeader(args, help) {

lib/primitives/tx.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,7 @@ class TX extends bio.Struct {
16711671

16721672
if (entry) {
16731673
height = entry.height;
1674-
block = entry.hash;
1674+
block = entry.hash.toString('hex');
16751675
time = entry.time;
16761676
date = util.date(time);
16771677
}

lib/primitives/txmeta.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class TXMeta extends bio.Struct {
132132
const json = this.tx.getJSON(network, view, null, this.index);
133133
json.mtime = this.mtime;
134134
json.height = this.height;
135-
json.block = this.block ? this.block : null;
135+
json.block = this.block ? this.block.toString('hex') : null;
136136
json.time = this.time;
137137
json.confirmations = 0;
138138

test/txmeta-test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const TXMeta = require('../lib/primitives/txmeta');
1010
const network = Network.get('regtest');
1111

1212
describe('TXMeta', function() {
13-
it('should return JSON for txmeta', async () => {
13+
it('should return correct confirmations', async () => {
1414
// unconfirmed at height 100
1515
const txmeta1 = new TXMeta();
1616
const txJSON1 = txmeta1.getJSON(network, null, 100);
@@ -22,4 +22,13 @@ describe('TXMeta', function() {
2222
const txJSON2 = txmeta2.getJSON(network, null, 100);
2323
assert.strictEqual(txJSON2.confirmations, 1);
2424
});
25+
26+
it('should return blockhash as string', async () => {
27+
// confirmed once at height 100
28+
const block = Buffer.from('058f5cf9187d9f60729245956688022474ffc0eda80df6340a2053d5c4d149af');
29+
const txmeta2 = TXMeta.fromOptions({ block });
30+
const txJSON2 = txmeta2.getJSON(network, null, null);
31+
32+
assert.strictEqual(txJSON2.block, block.toString('hex'));
33+
});
2534
});

0 commit comments

Comments
 (0)