Add binformat and corresponding generator script.

This commit is contained in:
Stefan Thomas
2013-01-25 15:18:54 +01:00
parent 3066a895c1
commit bd71489032
3 changed files with 419 additions and 0 deletions

182
src/js/binformat.js Normal file
View File

@@ -0,0 +1,182 @@
var ST = require("./serializedtypes");
var REQUIRED = 0,
OPTIONAL = 1,
DEFAULT = 2,
CloseResolution = ['CloseResolution' , ST.Int8, 1],
TemplateEntryType = ['TemplateEntryType' , ST.Int8, 2],
TransactionResult = ['TransactionResult' , ST.Int8, 3],
LedgerEntryType = ['LedgerEntryType' , ST.Int16, 1],
TransactionType = ['TransactionType' , ST.Int16, 2],
Flags = ['Flags' , ST.Int32, 2],
SourceTag = ['SourceTag' , ST.Int32, 3],
Sequence = ['Sequence' , ST.Int32, 4],
PreviousTxnLgrSeq = ['PreviousTxnLgrSeq' , ST.Int32, 5],
LedgerSequence = ['LedgerSequence' , ST.Int32, 6],
CloseTime = ['CloseTime' , ST.Int32, 7],
ParentCloseTime = ['ParentCloseTime' , ST.Int32, 8],
SigningTime = ['SigningTime' , ST.Int32, 9],
Expiration = ['Expiration' , ST.Int32, 10],
TransferRate = ['TransferRate' , ST.Int32, 11],
WalletSize = ['WalletSize' , ST.Int32, 12],
OwnerCount = ['OwnerCount' , ST.Int32, 13],
DestinationTag = ['DestinationTag' , ST.Int32, 14],
HighQualityIn = ['HighQualityIn' , ST.Int32, 16],
HighQualityOut = ['HighQualityOut' , ST.Int32, 17],
LowQualityIn = ['LowQualityIn' , ST.Int32, 18],
LowQualityOut = ['LowQualityOut' , ST.Int32, 19],
QualityIn = ['QualityIn' , ST.Int32, 20],
QualityOut = ['QualityOut' , ST.Int32, 21],
StampEscrow = ['StampEscrow' , ST.Int32, 22],
BondAmount = ['BondAmount' , ST.Int32, 23],
LoadFee = ['LoadFee' , ST.Int32, 24],
OfferSequence = ['OfferSequence' , ST.Int32, 25],
LastLedgerSequence = ['LastLedgerSequence' , ST.Int32, 27],
TransactionIndex = ['TransactionIndex' , ST.Int32, 28],
OperationLimit = ['OperationLimit' , ST.Int32, 29],
ReferenceFeeUnits = ['ReferenceFeeUnits' , ST.Int32, 30],
ReserveBase = ['ReserveBase' , ST.Int32, 31],
ReserveIncrement = ['ReserveIncrement' , ST.Int32, 32],
IndexNext = ['IndexNext' , ST.Int64, 1],
IndexPrevious = ['IndexPrevious' , ST.Int64, 2],
BookNode = ['BookNode' , ST.Int64, 3],
OwnerNode = ['OwnerNode' , ST.Int64, 4],
BaseFee = ['BaseFee' , ST.Int64, 5],
ExchangeRate = ['ExchangeRate' , ST.Int64, 6],
LowNode = ['LowNode' , ST.Int64, 7],
HighNode = ['HighNode' , ST.Int64, 8],
EmailHash = ['EmailHash' , ST.Hash128, 1],
LedgerHash = ['LedgerHash' , ST.Hash256, 1],
ParentHash = ['ParentHash' , ST.Hash256, 2],
TransactionHash = ['TransactionHash' , ST.Hash256, 3],
AccountHash = ['AccountHash' , ST.Hash256, 4],
PreviousTxnID = ['PreviousTxnID' , ST.Hash256, 5],
LedgerIndex = ['LedgerIndex' , ST.Hash256, 6],
WalletLocator = ['WalletLocator' , ST.Hash256, 7],
RootIndex = ['RootIndex' , ST.Hash256, 8],
BookDirectory = ['BookDirectory' , ST.Hash256, 16],
InvoiceID = ['InvoiceID' , ST.Hash256, 17],
Nickname = ['Nickname' , ST.Hash256, 18],
Feature = ['Feature' , ST.Hash256, 19],
TakerPaysCurrency = ['TakerPaysCurrency' , ST.Hash160, 1],
TakerPaysIssuer = ['TakerPaysIssuer' , ST.Hash160, 2],
TakerGetsCurrency = ['TakerGetsCurrency' , ST.Hash160, 3],
TakerGetsIssuer = ['TakerGetsIssuer' , ST.Hash160, 4],
Amount = ['Amount' , ST.Amount, 1],
Balance = ['Balance' , ST.Amount, 2],
LimitAmount = ['LimitAmount' , ST.Amount, 3],
TakerPays = ['TakerPays' , ST.Amount, 4],
TakerGets = ['TakerGets' , ST.Amount, 5],
LowLimit = ['LowLimit' , ST.Amount, 6],
HighLimit = ['HighLimit' , ST.Amount, 7],
Fee = ['Fee' , ST.Amount, 8],
SendMax = ['SendMax' , ST.Amount, 9],
MinimumOffer = ['MinimumOffer' , ST.Amount, 16],
RippleEscrow = ['RippleEscrow' , ST.Amount, 17],
PublicKey = ['PublicKey' , ST.VariableLength, 1],
MessageKey = ['MessageKey' , ST.VariableLength, 2],
SigningPubKey = ['SigningPubKey' , ST.VariableLength, 3],
TxnSignature = ['TxnSignature' , ST.VariableLength, 4],
Generator = ['Generator' , ST.VariableLength, 5],
Signature = ['Signature' , ST.VariableLength, 6],
Domain = ['Domain' , ST.VariableLength, 7],
FundCode = ['FundCode' , ST.VariableLength, 8],
RemoveCode = ['RemoveCode' , ST.VariableLength, 9],
ExpireCode = ['ExpireCode' , ST.VariableLength, 10],
CreateCode = ['CreateCode' , ST.VariableLength, 11],
Account = ['Account' , ST.Account, 1],
Owner = ['Owner' , ST.Account, 2],
Destination = ['Destination' , ST.Account, 3],
Issuer = ['Issuer' , ST.Account, 4],
Target = ['Target' , ST.Account, 7],
RegularKey = ['RegularKey' , ST.Account, 8],
Paths = ['Paths' , ST.PathSet, 1],
Indexes = ['Indexes' , ST.Vector256, 1],
Hashes = ['Hashes' , ST.Vector256, 2],
TransactionMetaData = ['TransactionMetaData' , ST.Object, 2],
CreatedNode = ['CreatedNode' , ST.Object, 3],
DeletedNode = ['DeletedNode' , ST.Object, 4],
ModifiedNode = ['ModifiedNode' , ST.Object, 5],
PreviousFields = ['PreviousFields' , ST.Object, 6],
FinalFields = ['FinalFields' , ST.Object, 7],
NewFields = ['NewFields' , ST.Object, 8],
TemplateEntry = ['TemplateEntry' , ST.Object, 9],
SigningAccounts = ['SigningAccounts' , ST.Array, 2],
TxnSignatures = ['TxnSignatures' , ST.Array, 3],
Signatures = ['Signatures' , ST.Array, 4],
Template = ['Template' , ST.Array, 5],
Necessary = ['Necessary' , ST.Array, 6],
Sufficient = ['Sufficient' , ST.Array, 7],
AffectedNodes = ['AffectedNodes' , ST.Array, 8],
Features = ['Features' , ST.Array, 9],
base = [
[ TransactionType , REQUIRED ],
[ Flags , OPTIONAL ],
[ SourceTag , OPTIONAL ],
[ Account , REQUIRED ],
[ Sequence , REQUIRED ],
[ Fee , REQUIRED ],
[ OperationLimit , OPTIONAL ],
[ SigningPubKey , REQUIRED ],
[ TxnSignature , OPTIONAL ]
];
exports.tx = {
AccountSet: [3].concat(base, [
[ EmailHash , OPTIONAL ],
[ WalletLocator , OPTIONAL ],
[ WalletSize , OPTIONAL ],
[ MessageKey , OPTIONAL ],
[ Domain , OPTIONAL ],
[ TransferRate , OPTIONAL ]
],
TrustSet: [20].concat(base, [
[ LimitAmount , OPTIONAL ],
[ QualityIn , OPTIONAL ],
[ QualityOut , OPTIONAL ]
],
OfferCreate: [7].concat(base, [
[ TakerPays , REQUIRED ],
[ TakerGets , REQUIRED ],
[ Expiration , OPTIONAL ]
],
OfferCancel: [8].concat(base, [
[ OfferSequence , REQUIRED ]
],
SetRegularKey: [5].concat(base, [
[ RegularKey , REQUIRED ]
],
Payment: [0].concat(base, [
[ Destination , REQUIRED ],
[ Amount , REQUIRED ],
[ SendMax , OPTIONAL ],
[ Paths , DEFAULT ],
[ InvoiceID , OPTIONAL ],
[ DestinationTag , OPTIONAL ]
],
Contract: [9].concat(base, [
[ Expiration , REQUIRED ],
[ BondAmount , REQUIRED ],
[ StampEscrow , REQUIRED ],
[ RippleEscrow , REQUIRED ],
[ CreateCode , OPTIONAL ],
[ FundCode , OPTIONAL ],
[ RemoveCode , OPTIONAL ],
[ ExpireCode , OPTIONAL ]
],
RemoveContract: [10].concat(base, [
[ Target , REQUIRED ]
],
EnableFeature: [100].concat(base, [
[ Feature , REQUIRED ]
],
SetFee: [101].concat(base, [
[ Features , REQUIRED ],
[ BaseFee , REQUIRED ],
[ ReferenceFeeUnits , REQUIRED ],
[ ReserveBase , REQUIRED ],
[ ReserveIncrement , REQUIRED ]
]
};

129
src/js/serializedtypes.js Normal file
View File

@@ -0,0 +1,129 @@
var SerializedType = function () {
};
exports.Int8 = new SerializedType({
serialize: function (so, val) {
return so.append([val & 0xff]);
},
parse: function (so) {
return so.read(1)[0];
}
});
exports.Int16 = new SerializedType({
serialize: function (so, val) {
// XXX
},
parse: function (so) {
// XXX
}
});
exports.Int32 = new SerializedType({
serialize: function (so, val) {
// XXX
},
parse: function (so) {
// XXX
}
});
exports.Int64 = new SerializedType({
serialize: function (so, val) {
// XXX
},
parse: function (so) {
// XXX
}
});
exports.Hash128 = new SerializedType({
serialize: function (so, val) {
// XXX
},
parse: function (so) {
// XXX
}
});
exports.Hash256 = new SerializedType({
serialize: function (so, val) {
// XXX
},
parse: function (so) {
// XXX
}
});
exports.Hash160 = new SerializedType({
serialize: function (so, val) {
// XXX
},
parse: function (so) {
// XXX
}
});
exports.Amount = new SerializedType({
serialize: function (so, val) {
// XXX
},
parse: function (so) {
// XXX
}
});
exports.VariableLength = new SerializedType({
serialize: function (so, val) {
// XXX
},
parse: function (so) {
// XXX
}
});
exports.Account = new SerializedType({
serialize: function (so, val) {
// XXX
},
parse: function (so) {
// XXX
}
});
exports.PathSet = new SerializedType({
serialize: function (so, val) {
// XXX
},
parse: function (so) {
// XXX
}
});
exports.Vector256 = new SerializedType({
serialize: function (so, val) {
// XXX
},
parse: function (so) {
// XXX
}
});
exports.Object = new SerializedType({
serialize: function (so, val) {
// XXX
},
parse: function (so) {
// XXX
}
});
exports.Array = new SerializedType({
serialize: function (so, val) {
// XXX
},
parse: function (so) {
// XXX
}
});