Skip to content

Commit

Permalink
Merge branch 'v0.8.3_shm' of github.com:TheArcadiaGroup/mesh-sdk-go i…
Browse files Browse the repository at this point in the history
…nto v0.8.3_shm
  • Loading branch information
khaihkd committed Jun 26, 2024
2 parents c91d70f + 04eae5e commit f5db30c
Show file tree
Hide file tree
Showing 269 changed files with 655 additions and 428 deletions.
22 changes: 11 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to rosetta-sdk-go
# Contributing to mesh-sdk-go

## Code of Conduct

Expand All @@ -10,11 +10,11 @@ You can contribute to this repository by asking questions, providing feedback, a

### Asking Questions

Submit your questions via the [Rosetta Community boards][13].
Submit your questions via the [Mesh Community boards][13].

### Providing Feedback

You can also use the [Rosetta Community boards][13] to provide feedback.
You can also use the [Mesh Community boards][13] to provide feedback.

### Reporting Issues

Expand Down Expand Up @@ -72,17 +72,17 @@ All support requests must be made via [our support team][3].
© 2022 Coinbase

<!-- Before adding link 15, populate link 4. One you do that, please erase this note. --->
[1]: https://github.com/coinbase/rosetta-sdk-go/issues
[1]: https://github.com/coinbase/mesh-sdk-go/issues
[2]: https://chris.beams.io/posts/git-commit/#seven-rules
[3]: https://support.coinbase.com/customer/en/portal/articles/2288496-how-can-i-contact-coinbase-support-
<!--- [4]: link removed --->
[5]: https://github.com/coinbase/rosetta-sdk-go/issues/new/choose
[6]: https://github.com/coinbase/rosetta-sdk-go/issues/new?assignees=&labels=bug&template=bug_report.md&title=
[7]: https://github.com/coinbase/rosetta-sdk-go/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=
[8]: https://github.com/coinbase/rosetta-sdk-go/pulls
[9]: https://github.com/coinbase/rosetta-sdk-go/compare
[5]: https://github.com/coinbase/mesh-sdk-go/issues/new/choose
[6]: https://github.com/coinbase/mesh-sdk-go/issues/new?assignees=&labels=bug&template=bug_report.md&title=
[7]: https://github.com/coinbase/mesh-sdk-go/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=
[8]: https://github.com/coinbase/mesh-sdk-go/pulls
[9]: https://github.com/coinbase/mesh-sdk-go/compare
[10]: https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/working-with-your-remote-repository-on-github-or-github-enterprise/creating-an-issue-or-pull-request#creating-an-issue
[11]: https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/working-with-your-remote-repository-on-github-or-github-enterprise/creating-an-issue-or-pull-request#creating-a-pull-request
[12]: https://hackerone.com/coinbase
[13]: https://community.rosetta-api.org
[14]: https://github.com/coinbase/rosetta-sdk-go/security
[13]: https://community.mesh-api.org
[14]: https://github.com/coinbase/mesh-sdk-go/security
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2020 Coinbase, Inc.
Copyright 2024 Coinbase, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
112 changes: 56 additions & 56 deletions README.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions asserter/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Asserter

[![GoDoc](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=shield)](https://pkg.go.dev/github.com/coinbase/rosetta-sdk-go/asserter?tab=doc)
[![GoDoc](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=shield)](https://pkg.go.dev/github.com/coinbase/mesh-sdk-go/asserter?tab=doc)

The Asserter package is used to validate the correctness of Rosetta types. It is
The Asserter package is used to validate the correctness of Mesh types. It is
important to note that this validation only ensures that required fields are
populated, fields are in the correct format, and transaction operations only
contain types and statuses specified in the /network/status endpoint.

If you want more intensive validation, try running the
[Rosetta CLI](https://github.com/coinbase/rosetta-cli).
[Mesh CLI](https://github.com/coinbase/mesh-cli).

## Installation

```shell
go get github.com/coinbase/rosetta-sdk-go/asserter
go get github.com/coinbase/mesh-sdk-go/asserter
```

## Validation file
Expand Down
2 changes: 1 addition & 1 deletion asserter/account.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion asserter/account_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
105 changes: 98 additions & 7 deletions asserter/asserter.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@ import (
"fmt"
"io/ioutil"
"path"
"strings"

"github.com/coinbase/rosetta-sdk-go/types"
)
Expand All @@ -35,11 +36,12 @@ type Asserter struct {
timestampStartIndex int64

// These variables are used for request assertion.
historicalBalanceLookup bool
supportedNetworks []*types.NetworkIdentifier
callMethods map[string]struct{}
mempoolCoins bool
validations *Validations
historicalBalanceLookup bool
supportedNetworks []*types.NetworkIdentifier
callMethods map[string]struct{}
mempoolCoins bool
validations *Validations
ignoreRosettaSpecValidation bool
}

// Validations is used to define stricter validations
Expand Down Expand Up @@ -120,6 +122,55 @@ func NewServer(
}, nil
}

// NewGenericAsserter constructs a new Asserter for generic usage
func NewGenericAsserter(
supportedOperationTypes []string,
historicalBalanceLookup bool,
supportedNetworks []*types.NetworkIdentifier,
operationStatuses []*types.OperationStatus,
errors []*types.Error,
genesisBlockIdentifier *types.BlockIdentifier,
timestampStartIndex int64,
validationFilePath string,
) (*Asserter, error) {
if err := OperationTypes(supportedOperationTypes); err != nil {
return nil, fmt.Errorf("operation types %v are invalid: %w", supportedOperationTypes, err)
}

if err := SupportedNetworks(supportedNetworks); err != nil {
return nil, fmt.Errorf(
"network identifiers %s are invalid: %w",
types.PrintStruct(supportedNetworks),
err,
)
}

validationConfig, err := getValidationConfig(validationFilePath)
if err != nil {
return nil, fmt.Errorf("config %s is invalid: %w", validationFilePath, err)
}

asserter := &Asserter{
operationTypes: supportedOperationTypes,
historicalBalanceLookup: historicalBalanceLookup,
supportedNetworks: supportedNetworks,
validations: validationConfig,
genesisBlock: genesisBlockIdentifier,
timestampStartIndex: timestampStartIndex,
}

asserter.errorTypeMap = map[int32]*types.Error{}
for _, err := range errors {
asserter.errorTypeMap[err.Code] = err
}
asserter.operationStatusMap = map[string]bool{}
for _, status := range operationStatuses {
asserter.operationStatusMap[status.Status] = status.Successful
}

return asserter, nil
}

// NewClientWithResponses constructs a new Asserter
// from a NetworkStatusResponse and
// NetworkOptionsResponse.
Expand Down Expand Up @@ -292,6 +343,43 @@ func NewClientWithOptions(
return asserter, nil
}

// NewGenericRosettaClient constructs a new Asserter using the provided
// arguments and without a Rosetta Spec validation. This is used to ignore rosetta spec validation
func NewGenericRosettaClient(
network *types.NetworkIdentifier,
genesisBlockIdentifier *types.BlockIdentifier,
) (*Asserter, error) {
if err := NetworkIdentifier(network); err != nil {
return nil, fmt.Errorf(
"network identifier %s is invalid: %w",
types.PrintStruct(network),
err,
)
}

if err := BlockIdentifier(genesisBlockIdentifier); err != nil {
return nil, fmt.Errorf(
"genesis block identifier %s is invalid: %w",
types.PrintStruct(genesisBlockIdentifier),
err,
)
}

asserter := &Asserter{
network: network,
genesisBlock: genesisBlockIdentifier,
validations: &Validations{
Enabled: false,
},
ignoreRosettaSpecValidation: true,
}

//init default operation statuses for generic rosetta client
InitOperationStatus(asserter)

return asserter, nil
}

// ClientConfiguration returns all variables currently set in an Asserter.
// This function will error if it is called on an uninitialized asserter.
func (a *Asserter) ClientConfiguration() (*Configuration, error) {
Expand Down Expand Up @@ -336,7 +424,10 @@ func (a *Asserter) OperationSuccessful(operation *types.Operation) (bool, error)

val, ok := a.operationStatusMap[*operation.Status]
if !ok {
return false, fmt.Errorf("operation status %s is not found", *operation.Status)
val, ok = a.operationStatusMap[strings.ToUpper(*operation.Status)]
if !ok {
return false, fmt.Errorf("operation status %s is not found", *operation.Status)
}
}

return val, nil
Expand Down
2 changes: 1 addition & 1 deletion asserter/asserter_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
8 changes: 4 additions & 4 deletions asserter/block.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -160,7 +160,7 @@ func (a *Asserter) OperationStatus(status *string, construction bool) error {
return ErrOperationStatusNotEmptyForConstruction
}

if _, ok := a.operationStatusMap[*status]; !ok {
if _, ok := a.operationStatusMap[*status]; !a.ignoreRosettaSpecValidation && !ok {
return fmt.Errorf("operation status %s is invalid: %w", *status, ErrOperationStatusInvalid)
}

Expand All @@ -174,7 +174,7 @@ func (a *Asserter) OperationType(t string) error {
return ErrAsserterNotInitialized
}

if t == "" || !containsString(a.operationTypes, t) {
if t == "" || (!a.ignoreRosettaSpecValidation && !containsString(a.operationTypes, t)) {
return fmt.Errorf("operation type %s is invalid: %w", t, ErrOperationTypeInvalid)
}

Expand Down Expand Up @@ -610,7 +610,7 @@ func (a *Asserter) Block(

// Only check for timestamp validity if timestamp start index is <=
// the current block index.
if a.timestampStartIndex <= block.BlockIdentifier.Index {
if !a.ignoreRosettaSpecValidation && a.timestampStartIndex <= block.BlockIdentifier.Index {
if err := Timestamp(block.Timestamp); err != nil {
return fmt.Errorf("timestamp %d is invalid: %w", block.Timestamp, err)
}
Expand Down
2 changes: 1 addition & 1 deletion asserter/block_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion asserter/coin.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion asserter/coin_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion asserter/construction.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion asserter/construction_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
6 changes: 5 additions & 1 deletion asserter/error.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,6 +33,10 @@ func (a *Asserter) Error(
return err
}

if a.ignoreRosettaSpecValidation {
return nil
}

val, ok := a.errorTypeMap[err.Code]
if !ok {
return fmt.Errorf(
Expand Down
2 changes: 1 addition & 1 deletion asserter/error_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion asserter/errors.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion asserter/errors_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion asserter/events.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion asserter/events_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion asserter/mempool.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion asserter/network.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion asserter/network_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Coinbase, Inc.
// Copyright 2024 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit f5db30c

Please sign in to comment.