mapArguments method
void
mapArguments(
- dynamic fn(
- dynamic arg,
- dynamic command,
- int commandIndex
)
)
Implementation
void mapArguments(
dynamic Function(dynamic arg, dynamic command, int commandIndex) fn,
) {
for (var commandIndex = 0; commandIndex < commands.length; commandIndex++) {
final command = commands[commandIndex];
if (command["MoveCall"] != null) {
command["MoveCall"]["arguments"] = command["MoveCall"]["arguments"]
.map((arg) => fn(arg, command, commandIndex))
.toList();
} else if (command["TransferObjects"] != null) {
command["TransferObjects"]["objects"] =
command["TransferObjects"]["objects"]
.map((arg) => fn(arg, command, commandIndex))
.toList();
command["TransferObjects"]["address"] = fn(
command["TransferObjects"]["address"],
command,
commandIndex,
);
} else if (command["SplitCoins"] != null) {
command["SplitCoins"]["coin"] = fn(
command["SplitCoins"]["coin"],
command,
commandIndex,
);
command["SplitCoins"]["amounts"] = command["SplitCoins"]["amounts"]
.map((arg) => fn(arg, command, commandIndex))
.toList();
} else if (command["MergeCoins"] != null) {
command["MergeCoins"]["destination"] = fn(
command["MergeCoins"]["destination"],
command,
commandIndex,
);
command["MergeCoins"]["sources"] = command["MergeCoins"]["sources"]
.map((arg) => fn(arg, command, commandIndex))
.toList();
} else if (command["MakeMoveVec"] != null) {
command["MakeMoveVec"]["elements"] = command["MakeMoveVec"]["elements"]
.map((arg) => fn(arg, command, commandIndex))
.toList();
} else if (command["Upgrade"] != null) {
command["Upgrade"]["ticket"] = fn(
command["Upgrade"]["ticket"],
command,
commandIndex,
);
} else if (command["\$Intent"] != null) {
final intentInputs = command["\$Intent"]["inputs"] as Map;
final mapped = <String, dynamic>{};
intentInputs.forEach((key, value) {
mapped[key] = value is Iterable
? value.map((arg) => fn(arg, command, commandIndex)).toList()
: fn(value, command, commandIndex);
});
command["\$Intent"]["inputs"] = mapped;
} else if (command["Publish"] != null) {
} else {
throw ArgumentError("Unexpected transaction kind: $command");
}
}
}