@ledgerhq/coin-mina
Version:
60 lines • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeTransferPayload = exports.buildAccountIdentifier = exports.addNetworkIdentifier = void 0;
const consts_1 = require("../../consts");
const addNetworkIdentifier = (data) => {
return {
...consts_1.MAINNET_NETWORK_IDENTIFIER,
...data,
};
};
exports.addNetworkIdentifier = addNetworkIdentifier;
const buildAccountIdentifier = (address) => {
return {
account_identifier: {
address,
metadata: {
token_id: consts_1.MINA_TOKEN_ID,
},
},
};
};
exports.buildAccountIdentifier = buildAccountIdentifier;
function makeTransferPayload(from, to, feeNano, valueNano) {
function makeOperation(idx, relatedIdxs, opType, addr, value, isPositive) {
const relatedOps = relatedIdxs.length == 0
? {}
: {
related_operations: relatedIdxs.map(i => {
return { index: i };
}),
};
return {
operation_identifier: { index: idx },
relatedOps,
type: opType,
account: {
address: addr,
metadata: {
token_id: consts_1.MINA_TOKEN_ID,
},
},
amount: {
value: (isPositive ? "" : "-") + value.toString(),
currency: {
symbol: consts_1.MINA_SYMBOL,
decimals: consts_1.MINA_DECIMALS,
},
},
};
}
return {
operations: [
makeOperation(0, [], "fee_payment", from, feeNano, false),
makeOperation(1, [], "payment_source_dec", from, valueNano, false),
makeOperation(2, [1], "payment_receiver_inc", to, valueNano, true),
],
};
}
exports.makeTransferPayload = makeTransferPayload;
//# sourceMappingURL=utils.js.map