export async function addAddress()

in cli-functions.js [93:120]


export async function addAddress(config, address, type = 'path') {
  let configPath = config;

  if (type === 'data') {
    const configFilename = path.join(os.tmpdir(), `config-${crypto.randomUUID()}.tmp`);
    fs.writeFileSync(configFilename, config);
    configPath = configFilename;
  }

  const command = 'rescontract';
  const cliArgs = ['add_address', '-c', configPath, '-e', address];

  try {
    const result = await handleExecFile(command, cliArgs);

    if (result.includes("Address added successfully")) {
      return "Address added successfully";
    } else {
      throw new Error("Failed to add address. Unexpected output: " + result);
    }
  } catch (error) {
    throw error;
  } finally {
    if (type === 'data' && fs.existsSync(configPath)) {
      fs.unlinkSync(configPath);
    }
  }
}