@radixdlt/tx-parser
Version:
Parsing of Radix Engine transactions and instructions
41 lines • 2.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Substate = void 0;
const _types_1 = require("./_types");
const tokens_1 = require("./tokens");
const preparedStake_1 = require("./preparedStake");
const preparedUnstake_1 = require("./preparedUnstake");
const stakeOwnership_1 = require("./stakeOwnership");
const validatorAllowDelegationFlag_1 = require("./validatorAllowDelegationFlag");
const validatorOwnerCopy_1 = require("./validatorOwnerCopy");
const LENGTH_BYTES = 2;
const TYPE_BYTES = 1;
const parseFromBufferReader = (bufferReader) => bufferReader
.readNextBuffer(LENGTH_BYTES + TYPE_BYTES)
.map(b => {
const lengthData = Buffer.from(b.slice(0, LENGTH_BYTES));
return [b.readUInt8(LENGTH_BYTES), lengthData];
})
.map(([type, lengthData]) => [type, lengthData])
.andThen(([substateType, lengthData]) => {
switch (substateType) {
case _types_1.SubStateType.TOKENS:
return tokens_1.Tokens.fromBufferReader(bufferReader, lengthData);
case _types_1.SubStateType.PREPARED_STAKE:
return preparedStake_1.PreparedStake.fromBufferReader(bufferReader, lengthData);
case _types_1.SubStateType.PREPARED_UNSTAKE:
return preparedUnstake_1.PreparedUnstake.fromBufferReader(bufferReader, lengthData);
case _types_1.SubStateType.STAKE_OWNERSHIP:
return stakeOwnership_1.StakeOwnership.fromBufferReader(bufferReader, lengthData);
case _types_1.SubStateType.VALIDATOR_ALLOW_DELEGATION_FLAG:
return validatorAllowDelegationFlag_1.ValidatorAllowDelegationFlag.fromBufferReader(bufferReader, lengthData);
case _types_1.SubStateType.VALIDATOR_OWNER_COPY:
return validatorOwnerCopy_1.ValidatorOwnerCopy.fromBufferReader(bufferReader, lengthData);
default:
throw new Error(`Substate ${substateType} of type: ${_types_1.SubStateType[substateType]} not implemented.`);
}
});
exports.Substate = {
parseFromBufferReader,
};
//# sourceMappingURL=substate.js.map