Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CommandArgumentError { arg_idx: 0, kind: InvalidResultArity { result_idx: 0 } } in command 1 #111

Open
qinheqing opened this issue May 16, 2023 · 1 comment

Comments

@qinheqing
Copy link

When transferring tokens, if there are many source objects, merge them first and then split the result into splitObjects. An error occurred during this step.

Argument splitCoin;
        if (sourceObjects.size() > 1) {
            Tuple3<ObjectID, SequenceNumber, ObjectDigest> destCoin = transactionBlock.getObjectRef(sourceObjects.get(0));
            List<Tuple3<ObjectID, SequenceNumber, ObjectDigest>> sourceCoins = sourceObjects.stream()
                    .skip(1)
                    .map(item -> transactionBlock.getObjectRef(item))
                    .collect(Collectors.toList());
            splitCoin = transactionBlock.mergeCoins(destCoin, sourceCoins);
        } else {
            splitCoin = transactionBlock.getObjectToArg(sourceObjects.get(0));
        }

        // splitCoins
        Argument argument = transactionBlock.splitCoinsNumber(splitCoin, Lists.newArrayList(amount));
        SuiAddress.Builder recipientAddressBuilder = new SuiAddress.Builder();
        recipientAddressBuilder.value = transactionBlock.geAddressBytes(recipient);
        transactionBlock.transferObjects(Lists.newArrayList(argument),
                transactionBlock.pure(recipientAddressBuilder.build()));

===== mergeCoins =======
  public Argument mergeCoins(
      Tuple3<ObjectID, SequenceNumber, ObjectDigest> destCoin,
      List<Tuple3<ObjectID, SequenceNumber, ObjectDigest>> sourceCoins) {
    ImmOrOwnedObject.Builder objectBuilder = new ImmOrOwnedObject.Builder();
    objectBuilder.value = destCoin;
    Argument dcoin = obj(objectBuilder.build());

    List<Argument> scoins =
        sourceCoins.stream()
            .map(
                objectRef -> {
                  ImmOrOwnedObject.Builder builder = new ImmOrOwnedObject.Builder();
                  builder.value = objectRef;
                  return obj(builder.build());
                })
            .collect(Collectors.toList());

    return mergeCoins(dcoin, scoins);
  }

image

I hope to get some advice.

@GrapeBaBa
Copy link
Owner

@qinheqing will check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants