runWithCmdCommands method
Run the program with args using the clvm tools commands
Implementation
Future<Output> runWithCmdCommands(Program args) async {
final programSource = await disassemble();
final argsSource = await args.disassemble();
final bridgeProgram =
await ChiaToolsCmds.brun(["-c", programSource, argsSource]);
final lines = bridgeProgram
.split("\n")
.map((e) => e.trim())
.where((element) => element.isNotEmpty)
.toList();
BigInt cost = BigInt.from(0);
if (lines.first.contains("cost = ")) {
final strCost = lines.first.split("cost = ").last;
cost = BigInt.parse(strCost);
}
String programWithOutPrefix = lines.last;
if (programWithOutPrefix.startsWith("0x")) {
programWithOutPrefix = programWithOutPrefix.substring(2);
}
return Output(
Program._(
sourceType: _ProgramSourceType.hex,
sourceValue: programWithOutPrefix,
),
cost);
}