Skip to content

Commit

Permalink
zeto: fix prepared transfers
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Richardson <[email protected]>
  • Loading branch information
awrichar committed Jan 16, 2025
1 parent 9211666 commit 17f2016
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
8 changes: 8 additions & 0 deletions domains/zeto/internal/zeto/handler_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/kaleido-io/paladin/domains/zeto/pkg/types"
"github.com/kaleido-io/paladin/domains/zeto/pkg/zetosigner/zetosignerapi"
"github.com/kaleido-io/paladin/toolkit/pkg/domain"
"github.com/kaleido-io/paladin/toolkit/pkg/prototk"
pb "github.com/kaleido-io/paladin/toolkit/pkg/prototk"
"github.com/kaleido-io/paladin/toolkit/pkg/tktypes"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -275,10 +276,17 @@ func (h *transferHandler) Prepare(ctx context.Context, tx *types.ParsedTransacti
return nil, err
}

var signer *string
if req.Transaction.Intent == prototk.TransactionSpecification_PREPARE_TRANSACTION {
// All "prepare" transactions must have an explicit "from" signer
signer = &req.Transaction.From
}

return &pb.PrepareTransactionResponse{
Transaction: &pb.PreparedTransaction{
FunctionAbiJson: string(functionJSON),
ParamsJson: string(paramsJSON),
RequiredSigner: signer,
},
}, nil
}
Expand Down
6 changes: 1 addition & 5 deletions example/bond/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,7 @@ async function main(): Promise<boolean> {
txID,
10000
);
if (paymentTransfer === undefined) {
logger.error("Failed!");
return false;
}
logger.log("Success!");
if (!paymentTransfer) return false;

if (paymentTransfer.transaction.to === undefined) {
logger.error("Prepared payment transfer had no 'to' address");
Expand Down
13 changes: 13 additions & 0 deletions sdk/typescript/src/domains/zeto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ export class ZetoInstance {
return this.paladin.pollForReceipt(txID, this.options.pollTimeout);
}

prepareTransfer(from: PaladinVerifier, data: ZetoTransferParams) {
return this.paladin.prepareTransaction({
type: TransactionType.PRIVATE,
abi: zetoAbi,
function: "transfer",
to: this.address,
from: from.lookup,
data: {
transfers: data.transfers.map((t) => ({ ...t, to: t.to.lookup })),
},
});
}

async lock(from: PaladinVerifier, data: ZetoLockParams) {
const txID = await this.paladin.sendTransaction({
type: TransactionType.PRIVATE,
Expand Down

0 comments on commit 17f2016

Please sign in to comment.