Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

SCP-2368: expose partial transactions that need to be balanced, signed and submitted by a remote wallet #119

Merged
merged 1 commit into from
Nov 25, 2021

Conversation

koslambrou
Copy link
Contributor

@koslambrou koslambrou commented Nov 16, 2021

First part of the hosted PAB scenario for a remote wallet client.

We expose partial transactions that need to be balanced, signed and submitted by the remote wallet.

What was done:

  • New WalletEffect, yieldUnbalancedTx, which makes available an unbalanced tx to be balanced, signed and then submitted to the blockchain.

  • Added ToJSON and FromJSON instances to ExportTx (partial tx)

  • Additionnal Generic and OpenAPI.ToSchema orphan instances for some cardano-api types.

  • New wallet handler in the PAB: RemoteClient. The only implemented wallet effect for the moment is YieldUnbalancedTx. The rest of the effects will be implemented in the future.

  • Changed the PAB wallet config settings which allows the user to specify if the wallet is available locally or remotely.

  • In the PAB, partial txs (ExportTx) are now exposed in the contract instance status endpoint (additionnaly as a NewYieldedPartialTx message in the websocket) when calling yieldUnbalancedTx.

Here's a simple setup to test this functionality:

1- In the plutus-pab.yaml config file, set the following attributes:

...
walletServerConfig:
  tag: RemoteWalletConfig
...
nodeServerConfig:
  ...
  mscNodeMode: AlonzoNode
...

2- Open a terminal and run cabal run plutus-pab:exe:plutus-pab-examples -- webserver --config plutus-pab/plutus-pab.yaml.sample

3- Open another terminal and execute the following shell script:

#!/usr/bin/env sh

INSTANCE_ID=$(curl -s -H "Content-Type: application/json" \
  --request POST \
  --data '{"caID": {"tag": "PayToWallet"}, "caWallet":{"getWalletId": "ffffffffffffffffffffffffffffffffffffffff"}}' \
  http://localhost:9080/api/contract/activate | jq -r '.unContractInstanceId')

curl -s http://localhost:9080/api/contract/instance/"$INSTANCE_ID"/status | jq

curl -H "Content-Type: application/json" \
  --request POST \
  --data '{"amount": {"getValue": [[{"unCurrencySymbol": ""}, [[{"unTokenName": ""}, 10000000]]]]}, "pkh": {"getPubKeyHash": "a2c20c77887ace1cd986193e4e75babd8993cfd56995cd5cfce609c2"}}' \
  'http://localhost:9080/api/contract/instance/'"$INSTANCE_ID"'/endpoint/PayToWallet'

sleep 1

curl -s http://localhost:9080/api/contract/instance/"$INSTANCE_ID"/status | jq

You should see a yielded tx similar the to following:

  "cicYieldedExportTxs": [
    {
      "transaction": "84a500800d80018182581d60a2c20c77887ace1cd986193e4e75babd8993cfd56995cd5cfce609c21a0098968002000e80a0f5f6",
      "redeemers": [],
      "inputs": []
    }
  ],

Pre-submit checklist:

  • Branch
    • Tests are provided (if possible)
    • Commit sequence broadly makes sense
    • Key commits have useful messages
    • Relevant tickets are mentioned in commit messages
    • Formatting, materialized Nix files, PNG optimization, etc. are updated
  • PR
    • Self-reviewed the diff
    • Useful pull request description
    • Reviewer requested

@koslambrou koslambrou changed the title WIP SCP-2368: expose partial transactions that need to be balanced, signed and submitted by a remote WIP SCP-2368: expose partial transactions that need to be balanced, signed and submitted by a remote wallet Nov 16, 2021
@koslambrou koslambrou force-pushed the scp-2368-pab-expose-url-tx-signed branch 3 times, most recently from 8690791 to 2ee1e00 Compare November 22, 2021 16:34
@koslambrou koslambrou changed the title WIP SCP-2368: expose partial transactions that need to be balanced, signed and submitted by a remote wallet SCP-2368: expose partial transactions that need to be balanced, signed and submitted by a remote wallet Nov 22, 2021
@koslambrou koslambrou marked this pull request as ready for review November 22, 2021 16:35
@koslambrou koslambrou force-pushed the scp-2368-pab-expose-url-tx-signed branch from 2ee1e00 to c67f1ca Compare November 22, 2021 17:49
Copy link
Contributor

@silky silky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! :)

@koslambrou koslambrou force-pushed the scp-2368-pab-expose-url-tx-signed branch 5 times, most recently from f630e96 to 9cd641e Compare November 24, 2021 15:37
… to be balanced, signed and submitted by a remote wallet.

* New WalletEffect, `yieldUnbalancedTx`, which makes available an unbalanced tx to be balanced, signed and then submitted to the blockchain.

* Added ToJSON and FromJSON instances to ExportTx (partial tx)

* Additionnal Generic and OpenAPI.ToSchema orphan instances for some cardano-api types.

* New wallet handler in the PAB: RemoteClient. The only implemented wallet effect for the moment is `YieldUnbalancedTx`. The rest of the effects will be implemented in the future.

* Changed the PAB wallet config settings which allows the user to specify if the wallet is available locally or remotely.

* In the PAB, partial txs (`ExportTx`) are now exposed in the contract instance status endpoint (additionnaly as a `NewYieldedPartialTx` message in the websocket) when calling `yieldUnbalancedTx`.

* Changed the PayToWallet example in plutus-pab to use `yieldUnbalancedTx`.
@koslambrou koslambrou force-pushed the scp-2368-pab-expose-url-tx-signed branch from 9cd641e to 5e76297 Compare November 24, 2021 16:31
@weskinner
Copy link
Contributor

I was able to reproduce locally, deserialize the transaction in the browser with cardano-serialization-lib, and sign the transaction with Nami wallet.

This branch of CSL was required to get it working: https://github.com/SundaeSwap-finance/cardano-serialization-lib/tree/fix-plutus-list-serialization

@koslambrou
Copy link
Contributor Author

Before merging, I need to find out why the tx encoding is always 84a5...f5f6 even thought is pass in different UnbalancedTx each time.

@koslambrou
Copy link
Contributor Author

My fault, the hex ARE different. Merging!

@koslambrou koslambrou merged commit a78e858 into main Nov 25, 2021
@koslambrou koslambrou deleted the scp-2368-pab-expose-url-tx-signed branch November 25, 2021 01:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants