2013-08-16 19:22:50 -07:00
|
|
|
require('classtool');
|
|
|
|
|
|
|
|
function ClassSpec(b) {
|
|
|
|
var superclass = b.superclass || require('./util/VersionedData').class();
|
|
|
|
|
|
|
|
|
|
|
|
function SIN(type, payload) {
|
|
|
|
if (typeof type != 'number') {
|
|
|
|
SIN.super(this, arguments);
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
this.data = new Buffer(1 + 1 + payload.length);
|
|
|
|
this.__proto__ = this.encodings['binary'];
|
2014-01-16 01:21:35 -08:00
|
|
|
this.prefix(0x0F); // SIN magic number, in numberspace
|
2013-08-16 19:22:50 -07:00
|
|
|
this.type(type);
|
|
|
|
this.payload(payload);
|
|
|
|
};
|
|
|
|
SIN.superclass = superclass;
|
|
|
|
superclass.applyEncodingsTo(SIN);
|
|
|
|
|
2014-01-16 01:21:35 -08:00
|
|
|
SIN.SIN_PERSIST_MAINNET = 0x01; // associated with sacrifice TX
|
|
|
|
SIN.SIN_PERSIST_TESTNET = 0x11; // associated with sacrifice TX
|
|
|
|
SIN.SIN_EPHEM = 0x02; // generate off-net at any time
|
2013-08-16 20:03:34 -07:00
|
|
|
|
2013-08-16 19:22:50 -07:00
|
|
|
// get or set the prefix data (the first byte of the address)
|
|
|
|
SIN.prototype.prefix = function(num) {
|
|
|
|
if(num || (num === 0)) {
|
|
|
|
this.doAsBinary(function() {this.data.writeUInt8(num, 0);});
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
return this.as('binary').readUInt8(0);
|
|
|
|
};
|
|
|
|
|
|
|
|
// get or set the SIN-type data (the second byte of the address)
|
|
|
|
SIN.prototype.type = function(num) {
|
|
|
|
if(num || (num === 0)) {
|
|
|
|
this.doAsBinary(function() {this.data.writeUInt8(num, 1);});
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
return this.as('binary').readUInt8(1);
|
|
|
|
};
|
|
|
|
|
|
|
|
// get or set the payload data (as a Buffer object)
|
|
|
|
SIN.prototype.payload = function(data) {
|
|
|
|
if(data) {
|
|
|
|
this.doAsBinary(function() {data.copy(this.data, 2);});
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
return this.as('binary').slice(1);
|
|
|
|
};
|
|
|
|
|
|
|
|
SIN.prototype.validate = function() {
|
|
|
|
this.doAsBinary(function() {
|
|
|
|
SIN.super(this, 'validate', arguments);
|
|
|
|
if (this.data.length != 22) throw new Error('invalid data length');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
return SIN;
|
|
|
|
};
|
|
|
|
module.defineClass(ClassSpec);
|