//  Copyright (C) 2018 Zilliqa
//
//  This file is part of zilliqa-js
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <https://www.gnu.org/licenses/>.
import { __assign, __rest } from "tslib";
import { TransactionError, } from '@zilliqa-js/core';
import { toChecksumAddress } from '@zilliqa-js/crypto';
import { BN, Long } from '@zilliqa-js/util';
export function toTxParams(response) {
    var _a = response.result, toAddr = _a.toAddr, senderPubKey = _a.senderPubKey, gasPrice = _a.gasPrice, gasLimit = _a.gasLimit, nonce = _a.nonce, amount = _a.amount, receipt = _a.receipt, version = _a.version, code = _a.code, data = _a.data, rest = __rest(_a, ["toAddr", "senderPubKey", "gasPrice", "gasLimit", "nonce", "amount", "receipt", "version", "code", "data"]);
    var msg = receipt.errors
        ? Object.keys(receipt.errors).reduce(function (acc, depth) {
            var _a;
            var errorMsgList = receipt.errors[depth].map(function (num) { return TransactionError[num]; });
            return __assign(__assign({}, acc), (_a = {}, _a[depth] = errorMsgList, _a));
        }, {})
        : {};
    return __assign(__assign({}, rest), { version: parseInt(version, 10), toAddr: toChecksumAddress(toAddr), pubKey: senderPubKey.replace('0x', ''), gasPrice: new BN(gasPrice), gasLimit: Long.fromString(gasLimit, 10), amount: new BN(amount), nonce: parseInt(nonce, 10), code: code, data: data, receipt: __assign(__assign({}, receipt), { accepted: receipt.accepted, errors: msg, cumulative_gas: parseInt(receipt.cumulative_gas, 10) }) });
}
//# sourceMappingURL=util.js.map