@kadena/kadena-cli
Version:
Kadena CLI tool to interact with the Kadena blockchain (manage keys, transactions, etc.)
34 lines • 1.73 kB
JavaScript
import path from 'node:path';
import { WORKING_DIRECTORY } from '../../../constants/config.js';
import { services } from '../../../services/index.js';
import { isPartiallySignedTransaction } from './txHelpers.js';
/**
* Saves multiple signed transactions
*/
export async function saveSignedTransactions(commands, options) {
var _a;
const result = [];
for (let index = 0; index < commands.length; index++) {
let command = commands[index];
const isPartial = isPartiallySignedTransaction(command);
const state = isPartial ? 'partial' : 'signed';
const fileDir = (_a = options === null || options === void 0 ? void 0 : options.directory) !== null && _a !== void 0 ? _a : WORKING_DIRECTORY;
const filePath = path.join(fileDir, `transaction-${command.hash.slice(0, 10)}-${state}.json`);
if (options === null || options === void 0 ? void 0 : options.chainweaverSignatures) {
console.log('chainweaverSignatures', command);
command = {
...command,
sigs: command.sigs.reduce((acc, sig, index) => {
var _a, _b;
const pubKey = (_a = sig === null || sig === void 0 ? void 0 : sig.pubKey) !== null && _a !== void 0 ? _a : JSON.parse(command.cmd).signers[index].pubKey;
acc[pubKey] = (_b = sig === null || sig === void 0 ? void 0 : sig.sig) !== null && _b !== void 0 ? _b : null;
return acc;
}, {}),
};
}
await services.filesystem.writeFile(filePath, JSON.stringify(command, null, 2));
result.push({ command, filePath, state });
}
return result;
}
//# sourceMappingURL=storage.js.map