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

Wasm exemplar #141

Merged
merged 6 commits into from
Oct 17, 2024
Merged

Wasm exemplar #141

merged 6 commits into from
Oct 17, 2024

Conversation

nitro-neal
Copy link
Contributor

@nitro-neal nitro-neal commented Oct 15, 2024

This pr implements the happy path polling flow for the typescript wasm pfi exemplar

PFI Output:

❯ npm run start:pfi

> [email protected] start:pfi
> tsc && node dist/pfi/index.js

offering signed and verified, ready for use
PFI server running on port 8082
GET /offerings
POST /exchanges
Replying with quote
GET /exchanges/rfq_01jabcfn7ae5krn501hz1jyahm
PUT /exchanges/rfq_01jabcfn7ae5krn501hz1jyahm
Replying with order instructions
Replying with order status: PAYIN_INITIATED
Replying with order status: PAYIN_SETTLED
Replying with order status: PAYOUT_INITIATED
Replying with order status: PAYOUT_SETTLED
Replying with close
GET /exchanges/rfq_01jabcfn7ae5krn501hz1jyahm
GET /exchanges/rfq_01jabcfn7ae5krn501hz1jyahm
GET /exchanges/rfq_01jabcfn7ae5krn501hz1jyahm

Wallet Output:

❯ npm run start:wallet

> [email protected] start:wallet
> tsc && node dist/wallet/index.js

(node:7906) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

~ Running Happy Path Polling Flow ~

1. Fetching offerings...
Successfully fetched offering ID: offering_01jabcf04pfsya3540wxk0eajy

2. Creating exchange...
Created exchange with ID: rfq_01jabcfn7ae5krn501hz1jyahm

3. Waiting for Quote...
Found quote!
Received quote with ID: quote_01jabcfnfrey6tc6hgbec0r7b4

4. Submitting order...
Order submitted with ID: order_01jabcfpzgfd1bab5888yhy4rx

5. Waiting for Order Instructions...
Found order instructions!
Received order instructions with ID: orderinstructions_01jabcfq3qe87vkafmxrrj7r96

6. Waiting for Order Status: PAYOUT_SETTLED...
Order status PAYOUT_SETTLED received.
Order status PAYOUT_SETTLED confirmed.

7. Waiting for Close...
Found close message!
Exchange closed with ID: close_01jabcfyfeeyxr3y26fvmtg765, Success: true

Exchange completed successfully!

There is a pretty big TODO:

the native library getExchange function is not working. I get a black hole WASM exception:

wasm://wasm/01161f7a:1


RuntimeError: unreachable
    at wasm://wasm/01161f7a:wasm-function[2105]:0x326aa0
    at wasm://wasm/01161f7a:wasm-function[3251]:0x35bd45
    at wasm://wasm/01161f7a:wasm-function[3327]:0x35cfc4
    at wasm://wasm/01161f7a:wasm-function[594]:0x1eb022
    at wasm://wasm/01161f7a:wasm-function[165]:0xe9398
    at wasm://wasm/01161f7a:wasm-function[1251]:0x2a5c00
    at wasm://wasm/01161f7a:wasm-function[3552]:0x36aff6
    at uA (file:///Users/nealr/MY-WORKSPACE/TBDEX-RS/tbdex-rs/bound/typescript/dist/index.mjs:2:424)
    at o (file:///Users/nealr/MY-WORKSPACE/TBDEX-RS/tbdex-rs/bound/typescript/dist/index.mjs:2:260)
    at node:internal/process/task_queues:140:7

Node.js v20.15.1

To get around this for now I do a manual call to our endpoint using axios -

const response = await axios.get('http://localhost:8082/exchanges/' + exchangeId);

I think it has to do with the rust code creating a bearer token.

I think it is crashing somewhere here:

pub async fn get_exchange(
    pfi_did_uri: &str,
    bearer_did: &BearerDid,
    exchange_id: &str,
) -> Result<Exchange> {
    let service_endpoint = get_service_endpoint(pfi_did_uri).await?;
    let get_exchange_endpoint = format!("{}/exchanges/{}", service_endpoint, exchange_id);

    let access_token = generate_access_token(pfi_did_uri, bearer_did)?;
    let get_exchange_response_body =
        get_json::<GetExchangeResponseBody>(&get_exchange_endpoint, Some(access_token)).await?;

    let mut exchange = Exchange::default();

    for message in get_exchange_response_body.data {
        match message {
            Message::Rfq(rfq) => {
                exchange.rfq = rfq;
            }
            Message::Quote(quote) => {
                exchange.quote = Some(quote);
            }
            Message::Order(order) => {
                exchange.order = Some(order);
            }
            Message::OrderInstructions(order_instructions) => {
                exchange.order_instructions = Some(order_instructions);
            }
            Message::Cancel(cancel) => {
                exchange.cancel = Some(cancel);
            }
            Message::OrderStatus(order_status) => {
                if let Some(order_statuses) = &mut exchange.order_statuses {
                    order_statuses.push(order_status);
                } else {
                    exchange.order_statuses = Some(vec![order_status]);
                }
            }
            Message::Close(close) => {
                exchange.close = Some(close);
            }
        }
    }

    Ok(exchange)
}

Copy link

github-actions bot commented Oct 15, 2024

TBD Spec Test Vectors Report (tbdex-rs)

Total Test VectorsTotal Test Cases✅ Passed❌ Failed⚠️ Skipped
109900
ℹ️ 9 out of 10 test vectors passed successfully.

❌ Missing Vectors (1)

These are test vectors without any test cases.
FeatureName
Protocolparse_orderinstructions

Automatically generated at: 2024-10-17T17:27:31.122Z

Copy link

github-actions bot commented Oct 15, 2024

TBD Spec Test Vectors Report (tbdex-core-kt)

Total Test VectorsTotal Test Cases✅ Passed❌ Failed⚠️ Skipped
10101000
✅ All test vectors passed
Automatically generated at: 2024-10-17T17:32:35.132Z

@nitro-neal nitro-neal marked this pull request as ready for review October 16, 2024 19:21
Copy link
Contributor

@KendallWeihe KendallWeihe left a comment

Choose a reason for hiding this comment

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

it lives!!!

@nitro-neal nitro-neal merged commit 83d762b into main Oct 17, 2024
20 checks passed
@nitro-neal nitro-neal deleted the wasm-exemplar branch October 17, 2024 17:36
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.

2 participants