bip70: details.getData.
This commit is contained in:
parent
0cbae18f1f
commit
8e5ca9f41e
@ -317,6 +317,43 @@ PaymentDetails.fromOptions = function fromOptions(options) {
|
|||||||
return new PaymentDetails().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) {
|
PaymentDetails.prototype.fromRaw = function fromRaw(data) {
|
||||||
var p = new ProtoReader(data);
|
var p = new ProtoReader(data);
|
||||||
var op, output;
|
var op, output;
|
||||||
@ -430,6 +467,9 @@ Payment.fromOptions = function fromOptions(options) {
|
|||||||
return new Payment().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) {
|
Payment.prototype.fromRaw = function fromRaw(data) {
|
||||||
var p = new ProtoReader(data);
|
var p = new ProtoReader(data);
|
||||||
var tx, op, output;
|
var tx, op, output;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user