bip70: details.getData.

This commit is contained in:
Christopher Jeffrey 2016-07-23 04:44:26 -07:00
parent 0cbae18f1f
commit 8e5ca9f41e
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -317,6 +317,43 @@ PaymentDetails.fromOptions = function fromOptions(options) {
return new PaymentDetails().fromOptions(options);
};
PaymentDetails.prototype.setData = function setData(data, enc) {
if (data == null || Buffer.isBuffer(data)) {
this.merchantData = data;
return;
}
if (enc === 'json') {
this.merchantData = new Buffer(JSON.stringify(data), 'utf8');
return;
}
assert(typeof data === 'string');
this.merchantData = new Buffer(data, enc);
};
PaymentDetails.prototype.getData = function getData(enc) {
var data = this.merchantData;
if (!data)
return;
if (!enc)
return data;
if (enc === 'json') {
data = data.toString('utf8');
try {
data = JSON.parse(data);
} catch (e) {
return;
}
return data;
}
return data.toString(enc);
};
PaymentDetails.prototype.fromRaw = function fromRaw(data) {
var p = new ProtoReader(data);
var op, output;
@ -430,6 +467,9 @@ Payment.fromOptions = function fromOptions(options) {
return new Payment().fromOptions(options);
};
Payment.prototype.setData = PaymentDetails.prototype.setData;
Payment.prototype.getData = PaymentDetails.prototype.getData;
Payment.prototype.fromRaw = function fromRaw(data) {
var p = new ProtoReader(data);
var tx, op, output;