"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.VoteTransaction = void 0;
const enums_1 = require("../../../enums");
const utils_1 = require("../../../utils");
const schemas = __importStar(require("../schemas"));
const transaction_1 = require("../transaction");
class VoteTransaction extends transaction_1.Transaction {
    static getSchema() {
        return schemas.vote;
    }
    serialize(options) {
        const { data } = this;
        const buff = new utils_1.ByteBuffer(Buffer.alloc(100));
        if (data.asset && data.asset.votes) {
            const voteBytes = data.asset.votes
                .map((vote) => (vote.startsWith("+") ? "01" : "00") + vote.slice(1))
                .join("");
            buff.writeUInt8(data.asset.votes.length);
            buff.writeBuffer(Buffer.from(voteBytes, "hex"));
        }
        return buff;
    }
    deserialize(buf) {
        const { data } = this;
        const votelength = buf.readUInt8();
        data.asset = { votes: [] };
        for (let i = 0; i < votelength; i++) {
            let vote = buf.readBuffer(34).toString("hex");
            vote = (vote[1] === "1" ? "+" : "-") + vote.slice(2);
            if (data.asset && data.asset.votes) {
                data.asset.votes.push(vote);
            }
        }
    }
}
exports.VoteTransaction = VoteTransaction;
VoteTransaction.typeGroup = enums_1.TransactionTypeGroup.Core;
VoteTransaction.type = enums_1.TransactionType.Vote;
VoteTransaction.key = "vote";
VoteTransaction.version = 1;
VoteTransaction.defaultStaticFee = utils_1.BigNumber.make("100000000");
//# sourceMappingURL=vote.js.map