Skip to content

Commit

Permalink
feat(flows): compat with ledger v1 (#1003)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag authored Dec 12, 2023
1 parent 9cd1bf7 commit 8a5be06
Show file tree
Hide file tree
Showing 55 changed files with 555 additions and 526 deletions.
6 changes: 3 additions & 3 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ deploy-all:
tests-all:
LOCALLY
FOR component IN $(cd ./components && ls -d */)
BUILD --pass-args ./components/${component}+tests
BUILD --pass-args ./components/${component}+tests
END
FOR component IN $(cd ./ee && ls -d */)
BUILD --pass-args ./ee/${component}+tests
BUILD --pass-args ./ee/${component}+tests
END

tests-integration:
Expand All @@ -154,7 +154,7 @@ pre-commit: # Generate the final spec and run all the pre-commit hooks
BUILD --pass-args ./components/${component}+pre-commit
END
FOR component IN $(cd ./ee && ls -d */)
BUILD --pass-args ./ee/${component}+pre-commit
BUILD --pass-args ./ee/${component}+pre-commit
END

pr:
Expand Down
36 changes: 36 additions & 0 deletions components/ledger/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,18 @@ paths:
"204":
description: No Content
content: {}
"400":
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
"404":
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
default:
description: Error
content:
Expand Down Expand Up @@ -607,6 +619,12 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/TransactionsResponse'
"400":
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
default:
description: Error
content:
Expand Down Expand Up @@ -682,6 +700,18 @@ paths:
"204":
description: No Content
content: {}
"400":
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
"404":
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
default:
description: Error
content:
Expand Down Expand Up @@ -724,6 +754,12 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/TransactionResponse'
"400":
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
default:
description: Error
content:
Expand Down
46 changes: 46 additions & 0 deletions components/ledger/openapi/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,21 @@ paths:
"204":
description: No Content
content: {}

"400":
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'

"404":
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'

default:
description: Error
content:
Expand Down Expand Up @@ -618,6 +633,14 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/TransactionsResponse'

"400":
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'

default:
description: Error
content:
Expand Down Expand Up @@ -695,6 +718,21 @@ paths:
"204":
description: No Content
content: {}

"400":
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'

"404":
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'

default:
description: Error
content:
Expand Down Expand Up @@ -738,6 +776,14 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/TransactionResponse'

"400":
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'

default:
description: Error
content:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@ type GetAccountRequest struct {
ID string `json:"id"`
}

func (a Activities) GetAccount(ctx context.Context, request GetAccountRequest) (*shared.V2AccountResponse, error) {
response, err := a.client.Ledger.V2GetAccount(
func (a Activities) GetAccount(ctx context.Context, request GetAccountRequest) (*shared.AccountResponse, error) {
response, err := a.client.Accounts.GetAccount(
ctx,
operations.V2GetAccountRequest{
operations.GetAccountRequest{
Address: request.ID,
Ledger: request.Ledger,
},
)
if err != nil {
switch err := err.(type) {
case *sdkerrors.V2ErrorResponse:
return nil, temporal.NewApplicationError(err.ErrorMessage, string(err.ErrorCode), err.Details)
case *sdkerrors.ErrorResponse:
return nil, temporal.NewApplicationError(*err.ErrorMessage, string(*err.ErrorCode), err.Details)
default:
return nil, err
}
}

return response.V2AccountResponse, nil
return response.AccountResponse, nil
}

var GetAccountActivity = Activities{}.GetAccount

func GetAccount(ctx workflow.Context, ledger, id string) (*shared.V2Account, error) {
ret := &shared.V2AccountResponse{}
func GetAccount(ctx workflow.Context, ledger, id string) (*shared.AccountWithVolumesAndBalances, error) {
ret := &shared.AccountResponse{}
if err := executeActivity(ctx, GetAccountActivity, ret, GetAccountRequest{
Ledger: ledger,
ID: id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,40 @@ type CreateTransactionWrapper struct {
}

type CreateTransactionRequest struct {
Ledger string `pathParam:"style=simple,explode=false,name=ledger"`
Data shared.V2PostTransaction `request:"mediaType=application/json"`
Ledger string `pathParam:"style=simple,explode=false,name=ledger"`
Data shared.PostTransaction `request:"mediaType=application/json"`
}

func (a Activities) CreateTransaction(ctx context.Context, request CreateTransactionRequest) (*shared.V2CreateTransactionResponse, error) {
func (a Activities) CreateTransaction(ctx context.Context, request CreateTransactionRequest) (*shared.TransactionsResponse, error) {

response, err := a.client.Ledger.V2CreateTransaction(
response, err := a.client.Transactions.CreateTransaction(
ctx,
operations.V2CreateTransactionRequest{
V2PostTransaction: request.Data,
Ledger: request.Ledger,
operations.CreateTransactionRequest{
PostTransaction: request.Data,
Ledger: request.Ledger,
},
)
if err != nil {
switch err := err.(type) {
case *sdkerrors.V2ErrorResponse:
return nil, temporal.NewApplicationError(err.ErrorMessage, string(err.ErrorCode), err.Details)
case *sdkerrors.ErrorResponse:
return nil, temporal.NewApplicationError(*err.ErrorMessage, string(*err.ErrorCode), err.Details)
default:
return nil, err
}
}

return response.V2CreateTransactionResponse, nil
return response.TransactionsResponse, nil
}

var CreateTransactionActivity = Activities{}.CreateTransaction

func CreateTransaction(ctx workflow.Context, ledger string, request shared.V2PostTransaction) (*shared.V2Transaction, error) {
tx := &shared.V2CreateTransactionResponse{}
func CreateTransaction(ctx workflow.Context, ledger string, request shared.PostTransaction) (*shared.Transaction, error) {
tx := &shared.TransactionsResponse{}
if err := executeActivity(ctx, CreateTransactionActivity, tx, CreateTransactionRequest{
Ledger: ledger,
Data: request,
}); err != nil {
return nil, err
}
return &tx.Data, nil
return &tx.Data[0], nil
}

This file was deleted.

Loading

1 comment on commit 8a5be06

@vercel
Copy link

@vercel vercel bot commented on 8a5be06 Dec 12, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.