├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md ├── dependabot.yml └── workflows │ └── ci.yml ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE.txt ├── Makefile ├── README.md ├── asserter ├── README.md ├── account.go ├── account_test.go ├── asserter.go ├── asserter_test.go ├── block.go ├── block_test.go ├── coin.go ├── coin_test.go ├── construction.go ├── construction_test.go ├── data │ ├── validation_balanced_related_ops.json │ ├── validation_fee_and_payment_balanced.json │ └── validation_fee_and_payment_unbalanced.json ├── error.go ├── error_test.go ├── errors.go ├── errors_test.go ├── events.go ├── events_test.go ├── mempool.go ├── network.go ├── network_test.go ├── operation_status.go ├── search.go ├── search_test.go ├── server.go ├── server_test.go └── utils.go ├── client ├── README.md ├── api_account.go ├── api_block.go ├── api_call.go ├── api_construction.go ├── api_events.go ├── api_mempool.go ├── api_network.go ├── api_search.go ├── client.go ├── configuration.go └── response.go ├── codegen.sh ├── constructor ├── errors ├── utils.go └── utils_test.go ├── examples ├── Makefile ├── README.md ├── client │ └── main.go ├── fetcher │ └── main.go └── server │ ├── main.go │ └── services │ ├── block_service.go │ └── network_service.go ├── fetcher ├── README.md ├── account.go ├── account_test.go ├── block.go ├── block_test.go ├── call.go ├── call_test.go ├── configuration.go ├── construction.go ├── errors.go ├── errors_test.go ├── events.go ├── events_test.go ├── fetcher.go ├── fetcher_test.go ├── mempool.go ├── network.go ├── network_test.go ├── search.go ├── search_test.go └── utils.go ├── go.mod ├── go.sum ├── headerforwarder ├── context.go ├── forwarder.go ├── forwarder_test.go ├── response_writer.go └── response_writer_test.go ├── imports.sh ├── keys ├── errors.go ├── errors_test.go ├── keys.go ├── keys_test.go ├── signer.go ├── signer_edwards25519.go ├── signer_edwards25519_test.go ├── signer_pallas.go ├── signer_pallas_test.go ├── signer_secp256k1.go ├── signer_secp256k1_test.go ├── signer_secp256r1.go ├── signer_secp256r1_test.go └── types.go ├── mocks ├── constructor ├── reconciler │ ├── handler.go │ └── helper.go ├── storage │ ├── database │ │ ├── badger_option.go │ │ ├── commit_worker.go │ │ ├── database.go │ │ └── transaction.go │ └── modules │ │ ├── balance_storage_handler.go │ │ ├── balance_storage_helper.go │ │ ├── block_worker.go │ │ ├── broadcast_storage_handler.go │ │ ├── broadcast_storage_helper.go │ │ └── coin_storage_helper.go ├── syncer │ ├── handler.go │ └── helper.go └── utils │ ├── block_storage_helper.go │ └── fetcher_helper.go ├── parser ├── README.md ├── balance_changes.go ├── balance_changes_test.go ├── errors.go ├── errors_test.go ├── exemptions.go ├── exemptions_test.go ├── group_operations.go ├── group_operations_test.go ├── intent.go ├── intent_test.go ├── match_operations.go ├── match_operations_test.go └── parser.go ├── reconciler ├── README.md ├── configuration.go ├── errors.go ├── errors_test.go ├── reconciler.go ├── reconciler_test.go └── types.go ├── server ├── README.md ├── api.go ├── api_account.go ├── api_block.go ├── api_call.go ├── api_construction.go ├── api_events.go ├── api_mempool.go ├── api_network.go ├── api_search.go ├── logger.go └── routers.go ├── statefulsyncer ├── configuration.go └── stateful_syncer.go ├── storage ├── database │ ├── badger_database.go │ ├── badger_database_configuration.go │ ├── badger_database_test.go │ └── database.go ├── encoder │ ├── buffer_pool.go │ ├── encoder.go │ └── encoder_test.go ├── errors │ ├── errors.go │ └── errors_test.go └── modules │ ├── balance_storage.go │ ├── balance_storage_test.go │ ├── block_storage.go │ ├── block_storage_test.go │ ├── broadcast_storage.go │ ├── broadcast_storage_test.go │ ├── coin_storage.go │ ├── coin_storage_test.go │ ├── counter_storage.go │ ├── counter_storage_test.go │ ├── job_storage.go │ ├── job_storage_test.go │ ├── key_storage.go │ ├── key_storage_test.go │ └── utils.go ├── syncer ├── README.md ├── configuration.go ├── errors.go ├── errors_test.go ├── syncer.go ├── syncer_test.go └── types.go ├── templates ├── client │ ├── api.mustache │ ├── client.mustache │ ├── configuration.mustache │ ├── model.mustache │ ├── partial_header.mustache │ └── response.mustache ├── construction_derive_response.txt ├── construction_parse_response.txt ├── docs │ ├── client.md │ ├── server.md │ └── types.md ├── go.mod.types ├── marshal.txt ├── server │ ├── api.mustache │ ├── controller-api.mustache │ ├── logger.mustache │ ├── partial_header.mustache │ └── routers.mustache ├── signing_payload.txt └── types.txt ├── types ├── README.md ├── account_balance_request.go ├── account_balance_response.go ├── account_coin.go ├── account_coins_request.go ├── account_coins_response.go ├── account_currency.go ├── account_identifier.go ├── allow.go ├── amount.go ├── balance_exemption.go ├── block.go ├── block_event.go ├── block_event_type.go ├── block_identifier.go ├── block_request.go ├── block_response.go ├── block_transaction.go ├── block_transaction_request.go ├── block_transaction_response.go ├── call_request.go ├── call_response.go ├── case.go ├── coin.go ├── coin_action.go ├── coin_change.go ├── coin_identifier.go ├── construction_combine_request.go ├── construction_combine_response.go ├── construction_derive_request.go ├── construction_derive_response.go ├── construction_hash_request.go ├── construction_metadata_request.go ├── construction_metadata_response.go ├── construction_parse_request.go ├── construction_parse_response.go ├── construction_payloads_request.go ├── construction_payloads_response.go ├── construction_preprocess_request.go ├── construction_preprocess_response.go ├── construction_submit_request.go ├── currency.go ├── curve_type.go ├── direction.go ├── error.go ├── events_blocks_request.go ├── events_blocks_response.go ├── exemption_type.go ├── go.mod ├── go.sum ├── marshal_test.go ├── mempool_response.go ├── mempool_transaction_request.go ├── mempool_transaction_response.go ├── metadata_request.go ├── network_identifier.go ├── network_list_response.go ├── network_options_response.go ├── network_request.go ├── network_status_response.go ├── operation.go ├── operation_identifier.go ├── operation_status.go ├── operator.go ├── partial_block_identifier.go ├── peer.go ├── public_key.go ├── related_transaction.go ├── search_transactions_request.go ├── search_transactions_response.go ├── signature.go ├── signature_type.go ├── signing_payload.go ├── sub_account_identifier.go ├── sub_network_identifier.go ├── sync_status.go ├── transaction.go ├── transaction_identifier.go ├── transaction_identifier_response.go ├── types.go ├── utils.go ├── utils_test.go └── version.go └── utils ├── bst.go ├── bst_test.go ├── mutex_map.go ├── mutex_map_test.go ├── priority_mutex.go ├── priority_mutex_test.go ├── sharded_map.go ├── sharded_map_test.go ├── size.go ├── size_test.go ├── utils.go └── utils_test.go /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: 'bug' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | 12 | 13 | **To Reproduce** 14 | 15 | 16 | **Expected behavior** 17 | 18 | 19 | **Additional context** 20 | 21 | 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: 'enhancement' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | 12 | 13 | **Describe the solution you'd like** 14 | 15 | 16 | **Describe alternatives you've considered** 17 | 18 | 19 | **Additional context** 20 | 21 | 22 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Fixes # . 2 | 3 | ### Motivation 4 | 7 | 8 | ### Solution 9 | 12 | 13 | ### Open questions 14 | 17 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Coinbase, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | version: 2 16 | 17 | updates: 18 | - package-ecosystem: "gomod" 19 | directory: "/" 20 | schedule: 21 | interval: "daily" 22 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | 9 | env: 10 | go_version: 1.19 11 | GO111MODULE: on 12 | COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }} 13 | 14 | jobs: 15 | Build: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - uses: actions/checkout@v3 19 | - uses: actions/setup-go@v3 20 | with: 21 | go-version: ${{ env.go_version }} 22 | - run: make build 23 | Test: 24 | runs-on: ubuntu-latest 25 | steps: 26 | - uses: actions/checkout@v3 27 | - uses: actions/setup-go@v3 28 | with: 29 | go-version: ${{ env.go_version }} 30 | - run: make test 31 | Lint: 32 | runs-on: ubuntu-latest 33 | steps: 34 | - uses: actions/checkout@v3 35 | - uses: actions/setup-go@v3 36 | with: 37 | go-version: ${{ env.go_version }} 38 | - uses: golangci/golangci-lint-action@v3 39 | with: 40 | version: latest 41 | args: --timeout 3m 42 | 43 | Check-License: 44 | runs-on: ubuntu-latest 45 | steps: 46 | - uses: actions/checkout@v3 47 | with: 48 | version: latest 49 | - uses: actions/setup-go@v3 50 | with: 51 | go-version: ${{ env.go_version }} 52 | - run: make check-license 53 | 54 | Check-Format: 55 | runs-on: ubuntu-latest 56 | steps: 57 | - uses: actions/checkout@v3 58 | with: 59 | version: latest 60 | - run: make check-format 61 | 62 | Check-Gen: 63 | runs-on: ubuntu-latest 64 | steps: 65 | - uses: actions/checkout@v3 66 | with: 67 | version: latest 68 | - run: make check-gen 69 | 70 | Coverage: 71 | runs-on: ubuntu-latest 72 | steps: 73 | - uses: actions/checkout@v3 74 | with: 75 | version: latest 76 | - uses: actions/setup-go@v3 77 | with: 78 | go-version: ${{ env.go_version }} 79 | - run: make test-cover COVERALLS_TOKEN="$COVERALLS_TOKEN" 80 | 81 | Salus: 82 | runs-on: ubuntu-latest 83 | steps: 84 | - uses: actions/checkout@v3 85 | with: 86 | version: latest 87 | - run: make salus 88 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | c.out 2 | coverage.html 3 | 4 | examples/server/server 5 | examples/client/client 6 | examples/fetcher/fetcher 7 | 8 | .idea/ 9 | -------------------------------------------------------------------------------- /asserter/data/validation_balanced_related_ops.json: -------------------------------------------------------------------------------- 1 | { 2 | "enabled": true, 3 | "related_ops_exists": true, 4 | "chain_type": "account", 5 | "payment": { 6 | "name": "PAYMENT", 7 | "operation": { 8 | "count": 2, 9 | "should_balance": true 10 | } 11 | }, 12 | "fee": { 13 | "name": "FEE", 14 | "operation": { 15 | "count": 1, 16 | "should_balance": false 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /asserter/data/validation_fee_and_payment_balanced.json: -------------------------------------------------------------------------------- 1 | { 2 | "enabled": true, 3 | "related_ops_exists": false, 4 | "chain_type": "account", 5 | "payment": { 6 | "name": "PAYMENT", 7 | "operation": { 8 | "count": 2, 9 | "should_balance": true 10 | } 11 | }, 12 | "fee": { 13 | "name": "FEE", 14 | "operation": { 15 | "count": 1, 16 | "should_balance": false 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /asserter/data/validation_fee_and_payment_unbalanced.json: -------------------------------------------------------------------------------- 1 | { 2 | "enabled": true, 3 | "related_ops_exists": false, 4 | "chain_type": "account", 5 | "payment": { 6 | "name": "PAYMENT", 7 | "operation": { 8 | "count": 2, 9 | "should_balance": false 10 | } 11 | }, 12 | "fee": { 13 | "name": "FEE", 14 | "operation": { 15 | "count": 1, 16 | "should_balance": false 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /asserter/error.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package asserter 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/coinbase/rosetta-sdk-go/types" 21 | ) 22 | 23 | // Error ensures a *types.Error matches some error 24 | // provided in `/network/options`. 25 | func (a *Asserter) Error( 26 | err *types.Error, 27 | ) error { 28 | if a == nil { 29 | return ErrAsserterNotInitialized 30 | } 31 | 32 | if err := Error(err); err != nil { 33 | return err 34 | } 35 | 36 | if a.ignoreRosettaSpecValidation { 37 | return nil 38 | } 39 | 40 | val, ok := a.errorTypeMap[err.Code] 41 | if !ok { 42 | return fmt.Errorf( 43 | "code %d: %w", 44 | err.Code, 45 | ErrErrorUnexpectedCode, 46 | ) 47 | } 48 | 49 | if val.Message != err.Message { 50 | return fmt.Errorf( 51 | "expected %s actual %s: %w", 52 | val.Message, 53 | err.Message, 54 | ErrErrorMessageMismatch, 55 | ) 56 | } 57 | 58 | if val.Retriable != err.Retriable { 59 | return fmt.Errorf( 60 | "expected %s actual %s: %w", 61 | val.Message, 62 | err.Message, 63 | ErrErrorRetriableMismatch, 64 | ) 65 | } 66 | 67 | return nil 68 | } 69 | -------------------------------------------------------------------------------- /asserter/errors_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package asserter 16 | 17 | import ( 18 | "errors" 19 | "testing" 20 | 21 | "github.com/stretchr/testify/assert" 22 | ) 23 | 24 | func TestErr(t *testing.T) { 25 | var tests = map[string]struct { 26 | err error 27 | is bool 28 | source string 29 | }{ 30 | "account balance error": { 31 | err: ErrReturnedBlockHashMismatch, 32 | is: true, 33 | source: "account balance error", 34 | }, 35 | "block error": { 36 | err: ErrBlockIdentifierIsNil, 37 | is: true, 38 | source: "block error", 39 | }, 40 | "coin error": { 41 | err: ErrCoinChangeIsNil, 42 | is: true, 43 | source: "coin error", 44 | }, 45 | "construction error": { 46 | err: ErrConstructionMetadataResponseIsNil, 47 | is: true, 48 | source: "construction error", 49 | }, 50 | "network error": { 51 | err: ErrNetworkIdentifierIsNil, 52 | is: true, 53 | source: "network error", 54 | }, 55 | "server error": { 56 | err: ErrNoSupportedNetworks, 57 | is: true, 58 | source: "server error", 59 | }, 60 | "not an assert error": { 61 | err: errors.New("blah"), 62 | is: false, 63 | source: "", 64 | }, 65 | } 66 | 67 | for name, test := range tests { 68 | t.Run(name, func(t *testing.T) { 69 | is, source := Err(test.err) 70 | assert.Equal(t, test.is, is) 71 | assert.Equal(t, test.source, source) 72 | }) 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /asserter/events.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package asserter 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/coinbase/rosetta-sdk-go/types" 21 | ) 22 | 23 | // BlockEvent ensures a *types.BlockEvent 24 | // is valid. 25 | func BlockEvent( 26 | event *types.BlockEvent, 27 | ) error { 28 | if event.Sequence < 0 { 29 | return ErrSequenceInvalid 30 | } 31 | 32 | if err := BlockIdentifier(event.BlockIdentifier); err != nil { 33 | return fmt.Errorf( 34 | "block identifier %s is invalid: %w", 35 | types.PrintStruct(event.BlockIdentifier), 36 | err, 37 | ) 38 | } 39 | 40 | switch event.Type { 41 | case types.ADDED, types.REMOVED: 42 | default: 43 | return ErrBlockEventTypeInvalid 44 | } 45 | 46 | return nil 47 | } 48 | 49 | // EventsBlocksResponse ensures a *types.EventsBlocksResponse 50 | // is valid. 51 | func EventsBlocksResponse( 52 | response *types.EventsBlocksResponse, 53 | ) error { 54 | if response.MaxSequence < 0 { 55 | return ErrMaxSequenceInvalid 56 | } 57 | 58 | seq := int64(-1) 59 | for i, event := range response.Events { 60 | if err := BlockEvent(event); err != nil { 61 | return fmt.Errorf("block event %s is invalid: %w", types.PrintStruct(event), err) 62 | } 63 | 64 | if seq == -1 { 65 | seq = event.Sequence 66 | } 67 | 68 | if event.Sequence != seq+int64(i) { 69 | return ErrSequenceOutOfOrder 70 | } 71 | } 72 | 73 | return nil 74 | } 75 | -------------------------------------------------------------------------------- /asserter/mempool.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package asserter 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/coinbase/rosetta-sdk-go/types" 21 | ) 22 | 23 | // MempoolTransactions returns an error if any 24 | // types.TransactionIdentifier returns is missing a hash. 25 | // The correctness of each populated MempoolTransaction is 26 | // asserted by Transaction. 27 | func MempoolTransactions( 28 | transactions []*types.TransactionIdentifier, 29 | ) error { 30 | for _, t := range transactions { 31 | if err := TransactionIdentifier(t); err != nil { 32 | return fmt.Errorf("transaction identifier %s is invalid: %w", types.PrintStruct(t), err) 33 | } 34 | } 35 | 36 | return nil 37 | } 38 | -------------------------------------------------------------------------------- /asserter/operation_status.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package asserter 16 | 17 | const ( 18 | OperationStatusSuccess = "SUCCESS" 19 | OperationStatusOk = "OK" 20 | OperationStatusCompleted = "COMPLETED" 21 | OperationStatusFailed = "FAILED" 22 | OperationStatusFailure = "FAILURE" 23 | ) 24 | 25 | // InitOperationStatus initializes operation status map for a generic rosetta client 26 | func InitOperationStatus(asserter *Asserter) { 27 | asserter.operationStatusMap = map[string]bool{ 28 | OperationStatusSuccess: true, 29 | OperationStatusOk: true, 30 | OperationStatusCompleted: true, 31 | OperationStatusFailed: false, 32 | OperationStatusFailure: false, 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /asserter/search.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package asserter 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/coinbase/rosetta-sdk-go/types" 21 | ) 22 | 23 | // SearchTransactionsResponse ensures a 24 | // *types.SearchTransactionsResponse is valid. 25 | func (a *Asserter) SearchTransactionsResponse( 26 | response *types.SearchTransactionsResponse, 27 | ) error { 28 | if a == nil { 29 | return ErrAsserterNotInitialized 30 | } 31 | 32 | if response.NextOffset != nil && *response.NextOffset < 0 { 33 | return ErrNextOffsetInvalid 34 | } 35 | 36 | if response.TotalCount < 0 { 37 | return ErrTotalCountInvalid 38 | } 39 | 40 | for _, blockTransaction := range response.Transactions { 41 | if err := BlockIdentifier(blockTransaction.BlockIdentifier); err != nil { 42 | return fmt.Errorf( 43 | "block identifier %s is invalid: %w", 44 | types.PrintStruct(blockTransaction.BlockIdentifier), 45 | err, 46 | ) 47 | } 48 | 49 | if err := a.Transaction(blockTransaction.Transaction); err != nil { 50 | return fmt.Errorf( 51 | "transaction %s is invalid: %w", 52 | types.PrintStruct(blockTransaction.Transaction), 53 | err, 54 | ) 55 | } 56 | } 57 | 58 | return nil 59 | } 60 | -------------------------------------------------------------------------------- /client/README.md: -------------------------------------------------------------------------------- 1 | # Client 2 | 3 | [![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/client?tab=doc) 4 | 5 | The Client package reduces the work required to communicate with a Mesh server. 6 | 7 | If you want a higher-level interface that automatically asserts that server responses 8 | are correct, check out the [Fetcher](/fetcher). 9 | 10 | ## Installation 11 | 12 | ```shell 13 | go get github.com/coinbase/mesh-sdk-go/client 14 | ``` 15 | 16 | ## Examples 17 | Check out the [examples](/examples) to see how easy 18 | it is to connect to a Mesh server. 19 | -------------------------------------------------------------------------------- /client/response.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package client 18 | 19 | import ( 20 | "net/http" 21 | ) 22 | 23 | // APIResponse stores the API response returned by the server. 24 | type APIResponse struct { 25 | *http.Response `json:"-"` 26 | Message string `json:"message,omitempty"` 27 | // Operation is the name of the OpenAPI operation. 28 | Operation string `json:"operation,omitempty"` 29 | // RequestURL is the request URL. This value is always available, even if the 30 | // embedded *http.Response is nil. 31 | RequestURL string `json:"url,omitempty"` 32 | // Method is the HTTP method used for the request. This value is always 33 | // available, even if the embedded *http.Response is nil. 34 | Method string `json:"method,omitempty"` 35 | // Payload holds the contents of the response body (which may be nil or empty). 36 | // This is provided here as the raw response.Body() reader will have already 37 | // been drained. 38 | Payload []byte `json:"-"` 39 | } 40 | 41 | // NewAPIResponse returns a new APIResonse object. 42 | func NewAPIResponse(r *http.Response) *APIResponse { 43 | response := &APIResponse{Response: r} 44 | return response 45 | } 46 | 47 | // NewAPIResponseWithError returns a new APIResponse object with the provided error message. 48 | func NewAPIResponseWithError(errorMessage string) *APIResponse { 49 | response := &APIResponse{Message: errorMessage} 50 | return response 51 | } 52 | -------------------------------------------------------------------------------- /constructor/coordinator/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package coordinator 16 | 17 | import ( 18 | "errors" 19 | ) 20 | 21 | var ( 22 | // ErrNoAvailableJobs is returned when it is not possible 23 | // to process any jobs. If this is returned, you should wait 24 | // and retry. 25 | ErrNoAvailableJobs = errors.New("no jobs available") 26 | 27 | // ErrReturnFundsComplete is returned when it is not possible 28 | // to process any more ReturnFundsWorkflows or when there is no provided 29 | // ReturnsFundsWorkflow. 30 | ErrReturnFundsComplete = errors.New("return funds complete") 31 | 32 | // ErrDuplicateWorkflows is returned when 2 Workflows with the same name 33 | // are provided as an input to NewCoordinator. 34 | ErrDuplicateWorkflows = errors.New("duplicate workflows") 35 | 36 | // ErrIncorrectConcurrency is returned when CreateAccount or RequestFunds 37 | // have a concurrency greater than 1. 38 | ErrIncorrectConcurrency = errors.New("incorrect concurrency") 39 | 40 | // ErrInvalidConcurrency is returned when the concurrency of a Workflow 41 | // is <= 0. 42 | ErrInvalidConcurrency = errors.New("invalid concurrency") 43 | 44 | // ErrStalled is returned when the caller does not define 45 | // a CreateAccount and/or RequestFunds workflow and we run out 46 | // of available options (i.e. we can't do anything). 47 | ErrStalled = errors.New( 48 | "processing stalled, the request_funds and/or create_account workflow(s) are/is not defined properly", 49 | ) 50 | 51 | // ErrNoWorkflows is returned when no workflows are provided 52 | // during initialization. 53 | ErrNoWorkflows = errors.New("no workflows") 54 | 55 | // ErrSignersNotEmpty is returned when signers are not empty in unsigned transaction 56 | ErrSignersNotEmpty = errors.New("signers are not empty in unsigned transaction") 57 | ) 58 | -------------------------------------------------------------------------------- /constructor/dsl/dsl.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package dsl 16 | 17 | import ( 18 | "context" 19 | "errors" 20 | "fmt" 21 | "log" 22 | "os" 23 | "path" 24 | 25 | "github.com/coinbase/rosetta-sdk-go/constructor/job" 26 | ) 27 | 28 | const ( 29 | // RosettaFileExtension is the file extension for all constructor files. 30 | RosettaFileExtension = ".ros" 31 | ) 32 | 33 | // Parse loads a Rosetta constructor file and attempts 34 | // to parse it into []*job.Workflow. 35 | func Parse(ctx context.Context, file string) ([]*job.Workflow, *Error) { 36 | cleanedPath := path.Clean(file) 37 | fileExtension := path.Ext(cleanedPath) 38 | if fileExtension != RosettaFileExtension { 39 | return nil, &Error{ 40 | Err: fmt.Errorf( 41 | "expected file extension %s, got %s: %w", 42 | RosettaFileExtension, 43 | fileExtension, 44 | ErrIncorrectExtension, 45 | ), 46 | } 47 | } 48 | 49 | f, err := os.Open(cleanedPath) // #nosec G304 50 | if err != nil { 51 | return nil, &Error{Err: fmt.Errorf("can't open file %s: %w", cleanedPath, err)} 52 | } 53 | defer func() { 54 | if err := f.Close(); err != nil { 55 | log.Printf("could not close %s: %s\n", cleanedPath, err.Error()) 56 | } 57 | }() 58 | 59 | p := newParser(f) 60 | workflows := []*job.Workflow{} 61 | workflowNames := map[string]struct{}{} 62 | for ctx.Err() == nil { 63 | workflow, err := p.parseWorkflow(ctx, workflowNames) 64 | if errors.Is(err, ErrEOF) { 65 | return workflows, nil 66 | } 67 | if err != nil { 68 | return nil, &Error{ 69 | Err: err, 70 | Line: p.lineNumber, 71 | LineContents: p.lastLineRead, 72 | } 73 | } 74 | 75 | workflowNames[workflow.Name] = struct{}{} 76 | workflows = append(workflows, workflow) 77 | } 78 | 79 | return nil, &Error{Err: ctx.Err()} 80 | } 81 | -------------------------------------------------------------------------------- /constructor/dsl/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package dsl 16 | 17 | import ( 18 | "errors" 19 | "fmt" 20 | 21 | "github.com/fatih/color" 22 | ) 23 | 24 | // DSL Errors 25 | var ( 26 | ErrIncorrectExtension = errors.New("expected .ros file extension") 27 | 28 | ErrEOF = errors.New("reached end of file") 29 | ErrScanner = errors.New("scanner error") 30 | 31 | ErrUnexpectedEOF = errors.New("unexpected EOF") 32 | 33 | ErrSyntax = errors.New("incorrect syntax") 34 | 35 | ErrParsingWorkflowName = errors.New("cannot parse workflow name") 36 | ErrParsingWorkflowConcurrency = errors.New("cannot parse workflow concurrency") 37 | ErrDuplicateWorkflowName = errors.New("duplicate workflow name") 38 | 39 | ErrParsingScenarioName = errors.New("cannot parse scenario name") 40 | ErrDuplicateScenarioName = errors.New("duplicate scenario name") 41 | 42 | ErrInvalidActionType = errors.New("invalid action type") 43 | ErrCannotSetVariableWithoutOutput = errors.New("cannot set variable without output path") 44 | ErrVariableUndefined = errors.New("variable undefined") 45 | ErrInvalidMathSymbol = errors.New("invalid math symbol") 46 | ) 47 | 48 | // Error contains a parsing error and context about 49 | // where the error occurred in the file. 50 | type Error struct { 51 | Line int `json:"line"` 52 | LineContents string `json:"line_contents"` 53 | Err error `json:"err"` 54 | } 55 | 56 | // Log prints the *Error to the console in red. 57 | func (e *Error) Log() { 58 | message := fmt.Sprintf("CONSTRUCTION FILE PARSING FAILED!\nMessage: %s\n\n", e.Err.Error()) 59 | 60 | if e.Line > 0 { 61 | message = fmt.Sprintf("%sLine: %d\nLine Contents:%s\n\n", message, e.Line, e.LineContents) 62 | } 63 | 64 | color.Red(message) 65 | } 66 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/action_eof.ros: -------------------------------------------------------------------------------- 1 | request_funds(1){ 2 | find_account{ 3 | currency = { 4 | "symbol":"ETH", 5 | "decimals":18 6 | }; 7 | random_account = find_balance({ 8 | "minimum_balance":{ 9 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/action_invalid_set_1.ros: -------------------------------------------------------------------------------- 1 | request_funds(1){ 2 | find_account{ 3 | set_variable({ 4 | "symbol":"ETH", 5 | "decimals":18 6 | }); 7 | random_account = find_balance({ 8 | "minimum_balance":{ 9 | "value": "0", 10 | "currency": {{currency}} 11 | }, 12 | "create_limit":1 13 | }); 14 | }, 15 | // test comment 16 | request{ 17 | loaded_account = find_balance({ // test comment 2 // blah 18 | "account_identifier": {{random_account.account_identifier}}, 19 | "minimum_balance":{ 20 | "value": "10000000000000000", 21 | "currency": {{currency}} 22 | } 23 | }); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/action_invalid_set_2.ros: -------------------------------------------------------------------------------- 1 | request_funds(1){ 2 | find_account{ 3 | { 4 | "symbol":"ETH", 5 | "decimals":18 6 | }; 7 | random_account = find_balance({ 8 | "minimum_balance":{ 9 | "value": "0", 10 | "currency": {{currency}} 11 | }, 12 | "create_limit":1 13 | }); 14 | }, 15 | // test comment 16 | request{ 17 | loaded_account = find_balance({ // test comment 2 // blah 18 | "account_identifier": {{random_account.account_identifier}}, 19 | "minimum_balance":{ 20 | "value": "10000000000000000", 21 | "currency": {{currency}} 22 | } 23 | }); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/action_invalid_type.ros: -------------------------------------------------------------------------------- 1 | 2 | request_funds(1){ 3 | find_account{ 4 | currency = { 5 | "symbol":"ETH", 6 | "decimals":18 7 | }; 8 | random_account = cool_stuff({ 9 | "minimum_balance":{ 10 | "value": "0", 11 | "currency": {{currency}} 12 | }, 13 | "create_limit":1 14 | }); 15 | }, 16 | // test comment 17 | request{ 18 | loaded_account = find_balance({ // test comment 2 // blah 19 | "account_identifier": {{random_account.account_identifier}}, 20 | "minimum_balance":{ 21 | "value": "10000000000000000", 22 | "currency": {{currency}} 23 | } 24 | }); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/action_valid.ros: -------------------------------------------------------------------------------- 1 | create_account(1){ 2 | create{ 3 | network = {"network":"chrysalis-devnet", "blockchain":"iota"}; 4 | key = generate_key({"curve_type": "edwards25519"}); 5 | account = derive({ 6 | "network_identifier": {{network}}, 7 | "public_key": {{key.public_key}} 8 | }); 9 | } 10 | } -------------------------------------------------------------------------------- /constructor/dsl/testdata/action_variable_format.ros: -------------------------------------------------------------------------------- 1 | 2 | request_funds(1){ 3 | find_account{ 4 | currency = { 5 | "symbol":"ETH", 6 | "decimals":18 7 | }; 8 | env = load_env("MIN_BALANCE"); 9 | random_account = find_balance({ 10 | "minimum_balance":{ 11 | "value": "0", 12 | "currency": {{currency} 13 | }, 14 | "create_limit":1 15 | }); 16 | }, 17 | // test comment 18 | request{ 19 | loaded_account = find_balance({ // test comment 2 // blah 20 | "account_identifier": {{random_account.account_identifier}}, 21 | "minimum_balance":{ 22 | "value": "10000000000000000", 23 | "currency": {{currency}} 24 | } 25 | }); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/action_variable_undefined.ros: -------------------------------------------------------------------------------- 1 | request_funds(1){ 2 | find_account{ 3 | currency = { 4 | "symbol":"ETH", 5 | "decimals":18 6 | }; 7 | random_account = find_balance({ 8 | "minimum_balance":{ 9 | "value": "0", 10 | "currency": {{currency2}} 11 | }, 12 | "create_limit":1 13 | }); 14 | }, 15 | // test comment 16 | request{ 17 | loaded_account = find_balance({ // test comment 2 // blah 18 | "account_identifier": {{random_account.account_identifier}}, 19 | "minimum_balance":{ 20 | "value": "10000000000000000", 21 | "currency": {{currency}} 22 | } 23 | }); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/duplicate_scenario.ros: -------------------------------------------------------------------------------- 1 | 2 | request_funds(1){ 3 | find_account{ 4 | currency = {"symbol":"ETH", "decimals":18}; 5 | currency_2 = set_variable({"symbol":"ETH", "decimals":18}); // support both native and function 6 | random_account = find_balance({ 7 | "minimum_balance":{ 8 | "value": "0", 9 | "currency": {{currency}} 10 | }, 11 | "create_limit":1 12 | }); 13 | }, 14 | find_account{ 15 | // Show different ways to do math 16 | math_1 = math({ 17 | "operation": "subtraction", 18 | "left_value": "0", 19 | "right_value": "100" 20 | }); 21 | math_2 = 10 + {{math_1}}; 22 | math_3 = {{math_2}} - "20"; 23 | loaded_account = find_balance({ 24 | "account_identifier": {{random_account.account_identifier}}, 25 | "minimum_balance":{ 26 | "value": "10000000000000000", 27 | "currency": {{currency}} 28 | } 29 | }); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/duplicate_workflow.ros: -------------------------------------------------------------------------------- 1 | 2 | request_funds(1){ 3 | find_account{ 4 | currency = {"symbol":"ETH", "decimals":18}; 5 | currency_2 = set_variable({"symbol":"ETH", "decimals":18}); // support both native and function 6 | random_account = find_balance({ 7 | "minimum_balance":{ 8 | "value": "0", 9 | "currency": {{currency}} 10 | }, 11 | "create_limit":1 12 | }); 13 | }, 14 | request{ 15 | // Show different ways to do math 16 | math_1 = math({ 17 | "operation": "subtraction", 18 | "left_value": "0", 19 | "right_value": "100" 20 | }); 21 | math_2 = 10 + {{math_1}}; 22 | math_3 = {{math_2}} - "20"; 23 | loaded_account = find_balance({ 24 | "account_identifier": {{random_account.account_identifier}}, 25 | "minimum_balance":{ 26 | "value": "10000000000000000", 27 | "currency": {{currency}} 28 | } 29 | }); 30 | } 31 | } 32 | 33 | request_funds(1){ 34 | create_account{ 35 | network = {"network":"Ropsten", "blockchain":"Ethereum"}; 36 | key = generate_key({"curve_type": "secp256k1"}); 37 | account = derive({ 38 | "network_identifier": {{network}}, 39 | "public_key": {{key.public_key}} 40 | }); 41 | save_account({ 42 | "account_identifier": {{account.account_identifier}}, 43 | "keypair": {{key}} 44 | }); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/invalid_concurrency.ros: -------------------------------------------------------------------------------- 1 | request_funds(hello){ 2 | find_account{ 3 | currency = { 4 | "symbol":"ETH", 5 | "decimals":18 6 | }; 7 | random_account = find_balance({ 8 | "minimum_balance":{ 9 | "value": "0", 10 | "currency": {{currency}} 11 | }, 12 | "create_limit":1 13 | }); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/invalid_scenario_concurrency.ros: -------------------------------------------------------------------------------- 1 | request_funds(1){ 2 | find_account(10){ 3 | currency = { 4 | "symbol":"ETH", 5 | "decimals":18 6 | }; 7 | random_account = find_balance({ 8 | "minimum_balance":{ 9 | "value": "0", 10 | "currency": {{currency}} 11 | }, 12 | "create_limit":1 13 | }); 14 | }, 15 | // test comment 16 | request{ 17 | loaded_account = find_balance({ // test comment 2 // blah 18 | "account_identifier": {{random_account.account_identifier}}, 19 | "minimum_balance":{ 20 | "value": "10000000000000000", 21 | "currency": {{currency}} 22 | } 23 | }); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/missing_concurrency.ros: -------------------------------------------------------------------------------- 1 | request_funds{ 2 | find_account{ 3 | currency = { 4 | "symbol":"ETH", 5 | "decimals":18 6 | }; 7 | random_account = find_balance({ 8 | "minimum_balance":{ 9 | "value": "0", 10 | "currency": {{currency}} 11 | }, 12 | "create_limit":1 13 | }); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/missing_scenario_bracket.ros: -------------------------------------------------------------------------------- 1 | request_funds(1){ 2 | find_account 3 | currency = { 4 | "symbol":"ETH", 5 | "decimals":18 6 | }; 7 | random_account = find_balance({ 8 | "minimum_balance":{ 9 | "value": "0", 10 | "currency": {{currency}} 11 | }, 12 | "create_limit":1 13 | }); 14 | }, 15 | // test comment 16 | request{ 17 | loaded_account = find_balance({ // test comment 2 // blah 18 | "account_identifier": {{random_account.account_identifier}}, 19 | "minimum_balance":{ 20 | "value": "10000000000000000", 21 | "currency": {{currency}} 22 | } 23 | }); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/missing_scenario_name.ros: -------------------------------------------------------------------------------- 1 | request_funds(1){ 2 | { 3 | currency = { 4 | "symbol":"ETH", 5 | "decimals":18 6 | }; 7 | random_account = find_balance({ 8 | "minimum_balance":{ 9 | "value": "0", 10 | "currency": {{currency}} 11 | }, 12 | "create_limit":1 13 | }); 14 | }, 15 | // test comment 16 | request{ 17 | loaded_account = find_balance({ // test comment 2 // blah 18 | "account_identifier": {{random_account.account_identifier}}, 19 | "minimum_balance":{ 20 | "value": "10000000000000000", 21 | "currency": {{currency}} 22 | } 23 | }); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/missing_workflow_bracket.ros: -------------------------------------------------------------------------------- 1 | request_funds(1) 2 | find_account{ 3 | currency = { 4 | "symbol":"ETH", 5 | "decimals":18 6 | }; 7 | random_account = find_balance({ 8 | "minimum_balance":{ 9 | "value": "0", 10 | "currency": {{currency}} 11 | }, 12 | "create_limit":1 13 | }); 14 | }, 15 | // test comment 16 | request{ 17 | loaded_account = find_balance({ // test comment 2 // blah 18 | "account_identifier": {{random_account.account_identifier}}, 19 | "minimum_balance":{ 20 | "value": "10000000000000000", 21 | "currency": {{currency}} 22 | } 23 | }); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/missing_workflow_name.ros: -------------------------------------------------------------------------------- 1 | (1){ 2 | find_account{ 3 | currency = { 4 | "symbol":"ETH", 5 | "decimals":18 6 | }; 7 | random_account = find_balance({ 8 | "minimum_balance":{ 9 | "value": "0", 10 | "currency": {{currency}} 11 | }, 12 | "create_limit":1 13 | }); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/multiple_workflow.ros: -------------------------------------------------------------------------------- 1 | request_funds(1){ 2 | find_account{ 3 | currency = {"symbol":"ETH", "decimals":18}; 4 | currency_2 = set_variable({"symbol":"ETH", "decimals":18}); // support both native and function 5 | random_account = find_balance({ 6 | "minimum_balance":{ 7 | "value": "0", 8 | "currency": {{currency}} 9 | }, 10 | "create_limit":1 11 | }); 12 | }, 13 | request{ 14 | // Show different ways to do math 15 | math_1 = math({ 16 | "operation": "subtraction", 17 | "left_value": "0", 18 | "right_value": "100" 19 | }); 20 | math_2 = 10 + {{math_1}}; 21 | math_3 = {{math_2}} - "20"; 22 | math_4 = {{math_3}} * "5"; 23 | math_5 = {{math_4}} / "5"; 24 | loaded_account = find_balance({ 25 | "account_identifier": {{random_account.account_identifier}}, 26 | "minimum_balance":{ 27 | "value": "10000000000000000", 28 | "currency": {{currency}} 29 | } 30 | }); 31 | } 32 | } 33 | 34 | create_account(1){ 35 | create_account{ 36 | network = {"network":"Ropsten", "blockchain":"Ethereum"}; 37 | key = generate_key({"curve_type": "secp256k1"}); 38 | account = derive({ 39 | "network_identifier": {{network}}, 40 | "public_key": {{key.public_key}} 41 | }); 42 | save_account({ 43 | "account_identifier": {{account.account_identifier}}, 44 | "keypair": {{key}} 45 | }); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/scenario_eof.ros: -------------------------------------------------------------------------------- 1 | request_funds(1){ 2 | find_account{ 3 | currency = { 4 | "symbol":"ETH", 5 | "decimals":18 6 | }; 7 | random_account = find_balance({ 8 | "minimum_balance":{ 9 | "value": "0", 10 | "currency": {{currency}} 11 | }, 12 | "create_limit":1 13 | }); 14 | }, 15 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/scenario_eof_2.ros: -------------------------------------------------------------------------------- 1 | 2 | request_funds(1){ 3 | find_account{ 4 | currency = { 5 | "symbol":"ETH", 6 | "decimals":18 7 | }; 8 | random_account = find_balance({ 9 | "minimum_balance":{ 10 | "value": "0", 11 | "currency": {{currency}} 12 | }, 13 | "create_limit":1 14 | }); 15 | } 16 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/scenario_improper_continue.ros: -------------------------------------------------------------------------------- 1 | 2 | request_funds(1){ 3 | find_account{ 4 | currency = { 5 | "symbol":"ETH", 6 | "decimals":18 7 | }; 8 | random_account = find_balance({ 9 | "minimum_balance":{ 10 | "value": "0", 11 | "currency": {{currency}} 12 | }, 13 | "create_limit":1 14 | }); 15 | } 16 | // test comment 17 | request{ 18 | loaded_account = find_balance({ // test comment 2 // blah 19 | "account_identifier": {{random_account.account_identifier}}, 20 | "minimum_balance":{ 21 | "value": "10000000000000000", 22 | "currency": {{currency}} 23 | } 24 | }); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/simple.ros: -------------------------------------------------------------------------------- 1 | 2 | 3 | request_funds(1){ 4 | find_account{ 5 | currency = { 6 | "symbol":"ETH", 7 | "decimals":18 8 | }; 9 | set_blob({ 10 | "key":"currency", 11 | "value":{{currency}} 12 | }); 13 | fetched_currency = get_blob({ 14 | "key":"currency" 15 | }); 16 | env = load_env("MIN_BALANCE"); 17 | random_account = find_balance({ 18 | "minimum_balance":{ 19 | "value": "0", 20 | "currency": {{currency}} 21 | }, 22 | "create_limit":1 23 | }); 24 | }, 25 | // test comment 26 | request{ 27 | print_message({{find_account.suggested_fee}}); // test variables that could be injected from other scenarios 28 | varA = "hello"; 29 | varB = 10; 30 | varC = [{"type":"transfer"}]; 31 | varD = "10"; 32 | varE = {{find_account}}; 33 | loaded_account = find_balance({ // test comment 2 // blah 34 | "account_identifier": {{random_account.account_identifier}}, 35 | "minimum_balance":{ 36 | "value": "10000000000000000", 37 | "currency": {{currency}} 38 | } 39 | }); 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/trailing_text_scenario.ros: -------------------------------------------------------------------------------- 1 | request_funds(1){ 2 | find_account{hello 3 | currency = { 4 | "symbol":"ETH", 5 | "decimals":18 6 | }; 7 | random_account = find_balance({ 8 | "minimum_balance":{ 9 | "value": "0", 10 | "currency": {{currency}} 11 | }, 12 | "create_limit":1 13 | }); 14 | }, 15 | // test comment 16 | request{ 17 | loaded_account = find_balance({ // test comment 2 // blah 18 | "account_identifier": {{random_account.account_identifier}}, 19 | "minimum_balance":{ 20 | "value": "10000000000000000", 21 | "currency": {{currency}} 22 | } 23 | }); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /constructor/dsl/testdata/workflow_closing_syntax.ros: -------------------------------------------------------------------------------- 1 | 2 | request_funds(1){ 3 | find_account{ 4 | currency = { 5 | "symbol":"ETH", 6 | "decimals":18 7 | }; 8 | random_account = find_balance({ 9 | "minimum_balance":{ 10 | "value": "0", 11 | "currency": {{currency}} 12 | }, 13 | "create_limit":1 14 | }); 15 | }, 16 | // test comment 17 | request{ 18 | loaded_account = find_balance({ // test comment 2 // blah 19 | "account_identifier": {{random_account.account_identifier}}, 20 | "minimum_balance":{ 21 | "value": "10000000000000000", 22 | "currency": {{currency}} 23 | } 24 | }); 25 | } 26 | ) 27 | 28 | -------------------------------------------------------------------------------- /constructor/job/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package job 16 | 17 | import "errors" 18 | 19 | var ( 20 | // ErrNoBroadcastToConfirm is returned when there is no broadcast 21 | // to confirm in a job. 22 | ErrNoBroadcastToConfirm = errors.New("no broadcast to confirm") 23 | 24 | // ErrVariableNotFound is returned when a variable is not 25 | // present in a Job's state. 26 | ErrVariableNotFound = errors.New("variable not found") 27 | 28 | // ErrVariableIncorrectFormat is returned when a variable 29 | // is in the incorrect format (i.e. when we find an int 30 | // instead of a string). 31 | ErrVariableIncorrectFormat = errors.New("variable in incorrect format") 32 | 33 | // ErrUnableToCreateBroadcast is returned when it is not possible 34 | // to create a broadcast or check if a broadcast should be created 35 | // from a job. 36 | ErrUnableToCreateBroadcast = errors.New("unable to create broadcast") 37 | 38 | // ErrJobInWrongState is returned when a job is in wrong state 39 | ErrJobInWrongState = errors.New("job in wrong state") 40 | ) 41 | -------------------------------------------------------------------------------- /constructor/job/utils.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package job 16 | 17 | import ( 18 | "bytes" 19 | "encoding/json" 20 | "fmt" 21 | ) 22 | 23 | // UnmarshalInput attempts to strictly unmarshal some input 24 | // into output. 25 | func UnmarshalInput(input []byte, output interface{}) error { 26 | // To prevent silent erroring, we explicitly 27 | // reject any unknown fields. 28 | dec := json.NewDecoder(bytes.NewReader(input)) 29 | dec.DisallowUnknownFields() 30 | 31 | if err := dec.Decode(&output); err != nil { 32 | return fmt.Errorf("unable to decode: %w", err) 33 | } 34 | 35 | return nil 36 | } 37 | -------------------------------------------------------------------------------- /constructor/worker/populator.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package worker 16 | 17 | import ( 18 | "fmt" 19 | "log" 20 | "regexp" 21 | "strings" 22 | 23 | "github.com/tidwall/gjson" 24 | ) 25 | 26 | // PopulateInput populates user defined variables in the input 27 | // with their corresponding values from the execution state. 28 | func PopulateInput(state string, input string) (string, error) { 29 | re := regexp.MustCompile(`\{\{[^\}]*\}\}`) 30 | 31 | var err error 32 | input = re.ReplaceAllStringFunc(input, func(match string) string { 33 | // remove special characters 34 | match = strings.Replace(match, "{{", "", 1) 35 | match = strings.Replace(match, "}}", "", 1) 36 | 37 | value := gjson.Get(state, match) 38 | if !value.Exists() { 39 | err = fmt.Errorf("%s is not present in state: %w", match, ErrVariableNotFound) 40 | return "" 41 | } 42 | 43 | return value.Raw 44 | }) 45 | if err != nil { 46 | return "", fmt.Errorf("unable to insert variables: %w", err) 47 | } 48 | 49 | if !gjson.Valid(input) { 50 | log.Printf("invalid json: %s\n", input) 51 | return "", ErrInvalidJSON 52 | } 53 | 54 | return input, nil 55 | } 56 | -------------------------------------------------------------------------------- /errors/utils.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package errors 16 | 17 | import "errors" 18 | 19 | // FindError is used by the Err functions in each package 20 | // to determine if a particular error was thrown by that component 21 | func FindError(errorList []error, err error) bool { 22 | for _, k := range errorList { 23 | if errors.Is(err, k) { 24 | return true 25 | } 26 | } 27 | return false 28 | } 29 | -------------------------------------------------------------------------------- /errors/utils_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package errors 16 | 17 | import ( 18 | "errors" 19 | "testing" 20 | 21 | "github.com/stretchr/testify/assert" 22 | ) 23 | 24 | func TestErrParser(t *testing.T) { 25 | err1 := errors.New("error 1") 26 | err2 := errors.New("error 2") 27 | err3 := errors.New("error 3") 28 | 29 | var tests = map[string]struct { 30 | err error 31 | errList []error 32 | found bool 33 | }{ 34 | "intent error": { 35 | err: err1, 36 | errList: []error{err1, err2, err3}, 37 | found: true, 38 | }, 39 | "match operations error": { 40 | err: errors.New("this is not an error we expect to find"), 41 | errList: []error{err1, err2}, 42 | found: false, 43 | }, 44 | } 45 | 46 | for name, test := range tests { 47 | t.Run(name, func(t *testing.T) { 48 | found := FindError(test.errList, test.err) 49 | assert.Equal(t, test.found, found) 50 | }) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: client fetcher server 2 | 3 | client: 4 | go run client/main.go; 5 | 6 | fetcher: 7 | go run fetcher/main.go; 8 | 9 | server: 10 | go run server/main.go; 11 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | This folder demonstrates how to write a Mesh server and how 4 | to use either the Client package or Fetcher package to communicate 5 | with that server. 6 | 7 | ## Steps 8 | 1. Run `make server` 9 | 2. Run `make client` (in a new terminal window) 10 | 2. Run `make fetcher` (in a new terminal window) 11 | -------------------------------------------------------------------------------- /fetcher/README.md: -------------------------------------------------------------------------------- 1 | # Fetcher 2 | 3 | [![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/fetcher?tab=doc) 4 | 5 | The Fetcher package provides a simplified client interface to communicate 6 | with a Mesh server. It also provides automatic retries and concurrent block 7 | fetches. 8 | 9 | If you want a lower-level interface to communicate with a Mesh server, 10 | check out the [Client](/client). 11 | 12 | ## Installation 13 | 14 | ```shell 15 | go get github.com/coinbase/mesh-sdk-go/fetcher 16 | ``` 17 | 18 | ## Create a Fetcher 19 | Creating a basic Fetcher is as easy as providing a context and Mesh server URL: 20 | ```go 21 | fetcher := fetcher.New(ctx, serverURL) 22 | ``` 23 | 24 | It is also possible to provide a series of optional arguments that override 25 | default behavior. For example, it is possible to override the concurrency 26 | for making block requests: 27 | ```go 28 | fetcher := fetcher.New(ctx, serverURL, fetcher.WithBlockConcurrency(10)) 29 | ``` 30 | 31 | ## More Examples 32 | Check out the [examples](/examples) to see how easy 33 | it is to connect to a Mesh server. 34 | -------------------------------------------------------------------------------- /fetcher/errors_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package fetcher 16 | 17 | import ( 18 | "errors" 19 | "testing" 20 | 21 | "github.com/stretchr/testify/assert" 22 | ) 23 | 24 | func TestErr(t *testing.T) { 25 | var tests = map[string]struct { 26 | err error 27 | is bool 28 | }{ 29 | "is a keys error": { 30 | err: ErrNoNetworks, 31 | is: true, 32 | }, 33 | "not a keys error": { 34 | err: errors.New("blah"), 35 | is: false, 36 | }, 37 | } 38 | 39 | for name, test := range tests { 40 | t.Run(name, func(t *testing.T) { 41 | is := Err(test.err) 42 | assert.Equal(t, test.is, is) 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /headerforwarder/context.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package headerforwarder 16 | 17 | import ( 18 | "context" 19 | "net/http" 20 | 21 | "github.com/google/uuid" 22 | ) 23 | 24 | type contextKey string 25 | 26 | const requestIDKey = contextKey("request_id") 27 | 28 | const outgoingHeadersKey = contextKey("outgoing_headers") 29 | 30 | func ContextWithRosettaID(ctx context.Context) context.Context { 31 | return context.WithValue(ctx, requestIDKey, uuid.NewString()) 32 | } 33 | 34 | func RosettaIDFromContext(ctx context.Context) string { 35 | switch val := ctx.Value(requestIDKey).(type) { 36 | case string: 37 | return val 38 | default: 39 | return "" 40 | } 41 | } 42 | 43 | func RosettaIDFromRequest(r *http.Request) string { 44 | switch value := r.Context().Value(requestIDKey).(type) { 45 | case string: 46 | return value 47 | default: 48 | return "" 49 | } 50 | } 51 | 52 | // RequestWithRequestID adds a unique ID to the request context. A new request is returned that contains the 53 | // new context 54 | func RequestWithRequestID(req *http.Request) *http.Request { 55 | ctx := req.Context() 56 | ctxWithID := ContextWithRosettaID(ctx) 57 | requestWithID := req.WithContext(ctxWithID) 58 | 59 | return requestWithID 60 | } 61 | 62 | func ContextWithOutgoingHeaders(ctx context.Context, headers http.Header) context.Context { 63 | return context.WithValue(ctx, outgoingHeadersKey, headers) 64 | } 65 | 66 | func OutgoingHeadersFromContext(ctx context.Context) http.Header { 67 | switch val := ctx.Value(outgoingHeadersKey).(type) { 68 | case http.Header: 69 | return val 70 | default: 71 | return nil 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /imports.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2024 Coinbase, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | go install github.com/incu6us/goimports-reviser/v2@latest; 17 | 18 | while IFS= read -r -d '' FILE 19 | do 20 | goimports-reviser -file-path "${FILE}" -local github.com/coinbase/rosetta-sdk-go/ 21 | done < <(find . -type f -name "*.go" -print0) 22 | -------------------------------------------------------------------------------- /keys/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package keys 16 | 17 | import ( 18 | "errors" 19 | 20 | utils "github.com/coinbase/rosetta-sdk-go/errors" 21 | ) 22 | 23 | // Named error types for Keys errors 24 | var ( 25 | ErrPrivKeyUndecodable = errors.New("could not decode privkey") 26 | ErrPrivKeyLengthInvalid = errors.New("invalid privkey length") 27 | ErrPrivKeyZero = errors.New("privkey cannot be 0") 28 | ErrPubKeyNotOnCurve = errors.New("pubkey is not on the curve") 29 | 30 | ErrCurveTypeNotSupported = errors.New("not a supported CurveType") 31 | 32 | ErrSignUnsupportedPayloadSignatureType = errors.New( 33 | "sign: unexpected payload.SignatureType while signing", 34 | ) 35 | ErrSignUnsupportedSignatureType = errors.New( 36 | "sign: unexpected Signature type while signing", 37 | ) 38 | 39 | ErrVerifyUnsupportedPayloadSignatureType = errors.New( 40 | "verify: unexpected payload.SignatureType while verifying", 41 | ) 42 | ErrVerifyUnsupportedSignatureType = errors.New( 43 | "verify: unexpected Signature type while verifying", 44 | ) 45 | ErrVerifyFailed = errors.New("verify: verify returned false") 46 | 47 | ErrPaymentNotFound = errors.New("payment not found in signingPayload") 48 | ) 49 | 50 | // Err takes an error as an argument and returns 51 | // whether or not the error is one thrown by the keys package 52 | func Err(err error) bool { 53 | keyErrors := []error{ 54 | ErrPrivKeyUndecodable, 55 | ErrPrivKeyLengthInvalid, 56 | ErrPrivKeyZero, 57 | ErrPubKeyNotOnCurve, 58 | ErrCurveTypeNotSupported, 59 | ErrSignUnsupportedPayloadSignatureType, 60 | ErrSignUnsupportedSignatureType, 61 | ErrVerifyUnsupportedPayloadSignatureType, 62 | ErrVerifyUnsupportedSignatureType, 63 | ErrVerifyFailed, 64 | } 65 | 66 | return utils.FindError(keyErrors, err) 67 | } 68 | -------------------------------------------------------------------------------- /keys/errors_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package keys 16 | 17 | import ( 18 | "errors" 19 | "testing" 20 | 21 | "github.com/stretchr/testify/assert" 22 | ) 23 | 24 | func TestErr(t *testing.T) { 25 | var tests = map[string]struct { 26 | err error 27 | is bool 28 | }{ 29 | "is a keys error": { 30 | err: ErrPrivKeyLengthInvalid, 31 | is: true, 32 | }, 33 | "not a keys error": { 34 | err: errors.New("blah"), 35 | is: false, 36 | }, 37 | } 38 | 39 | for name, test := range tests { 40 | t.Run(name, func(t *testing.T) { 41 | is := Err(test.err) 42 | assert.Equal(t, test.is, is) 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /keys/signer.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package keys 16 | 17 | import "github.com/coinbase/rosetta-sdk-go/types" 18 | 19 | // Signer is an interface for different curve signers 20 | type Signer interface { 21 | PublicKey() *types.PublicKey 22 | Sign(payload *types.SigningPayload, sigType types.SignatureType) (*types.Signature, error) 23 | Verify(signature *types.Signature) error 24 | } 25 | -------------------------------------------------------------------------------- /keys/types.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package keys 16 | 17 | import ( 18 | "encoding/hex" 19 | "encoding/json" 20 | "fmt" 21 | 22 | "github.com/coinbase/rosetta-sdk-go/types" 23 | ) 24 | 25 | // KeyPair contains a PrivateKey and its associated PublicKey 26 | type KeyPair struct { 27 | PublicKey *types.PublicKey `json:"public_key"` 28 | PrivateKey []byte `json:"private_key"` 29 | } 30 | 31 | // MarshalJSON overrides the default JSON marshaler 32 | // and encodes bytes as hex instead of base64. 33 | func (k *KeyPair) MarshalJSON() ([]byte, error) { 34 | type Alias KeyPair 35 | j, err := json.Marshal(struct { 36 | PrivateKey string `json:"private_key"` 37 | *Alias 38 | }{ 39 | PrivateKey: hex.EncodeToString(k.PrivateKey), 40 | Alias: (*Alias)(k), 41 | }) 42 | if err != nil { 43 | return nil, fmt.Errorf("failed to marshal key pair: %w", err) 44 | } 45 | return j, nil 46 | } 47 | 48 | // UnmarshalJSON overrides the default JSON unmarshaler 49 | // and decodes bytes from hex instead of base64. 50 | func (k *KeyPair) UnmarshalJSON(b []byte) error { 51 | type Alias KeyPair 52 | r := struct { 53 | PrivateKey string `json:"private_key"` 54 | *Alias 55 | }{ 56 | Alias: (*Alias)(k), 57 | } 58 | err := json.Unmarshal(b, &r) 59 | if err != nil { 60 | return fmt.Errorf("failed to unmarshal key pair: %w", err) 61 | } 62 | bytes, err := hex.DecodeString(r.PrivateKey) 63 | if err != nil { 64 | return fmt.Errorf("failed to decode private key: %w", err) 65 | } 66 | k.PrivateKey = bytes 67 | return nil 68 | } 69 | -------------------------------------------------------------------------------- /mocks/constructor/coordinator/handler.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.13.1. DO NOT EDIT. 2 | 3 | package coordinator 4 | 5 | import ( 6 | context "context" 7 | 8 | mock "github.com/stretchr/testify/mock" 9 | 10 | types "github.com/coinbase/rosetta-sdk-go/types" 11 | ) 12 | 13 | // Handler is an autogenerated mock type for the Handler type 14 | type Handler struct { 15 | mock.Mock 16 | } 17 | 18 | // TransactionCreated provides a mock function with given fields: _a0, _a1, _a2 19 | func (_m *Handler) TransactionCreated(_a0 context.Context, _a1 string, _a2 *types.TransactionIdentifier) error { 20 | ret := _m.Called(_a0, _a1, _a2) 21 | 22 | var r0 error 23 | if rf, ok := ret.Get(0).(func(context.Context, string, *types.TransactionIdentifier) error); ok { 24 | r0 = rf(_a0, _a1, _a2) 25 | } else { 26 | r0 = ret.Error(0) 27 | } 28 | 29 | return r0 30 | } 31 | 32 | type mockConstructorTestingTNewHandler interface { 33 | mock.TestingT 34 | Cleanup(func()) 35 | } 36 | 37 | // NewHandler creates a new instance of Handler. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 38 | func NewHandler(t mockConstructorTestingTNewHandler) *Handler { 39 | mock := &Handler{} 40 | mock.Mock.Test(t) 41 | 42 | t.Cleanup(func() { mock.AssertExpectations(t) }) 43 | 44 | return mock 45 | } 46 | -------------------------------------------------------------------------------- /mocks/storage/database/badger_option.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.13.1. DO NOT EDIT. 2 | 3 | package database 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | 8 | database "github.com/coinbase/rosetta-sdk-go/storage/database" 9 | ) 10 | 11 | // BadgerOption is an autogenerated mock type for the BadgerOption type 12 | type BadgerOption struct { 13 | mock.Mock 14 | } 15 | 16 | // Execute provides a mock function with given fields: b 17 | func (_m *BadgerOption) Execute(b *database.BadgerDatabase) { 18 | _m.Called(b) 19 | } 20 | 21 | type mockConstructorTestingTNewBadgerOption interface { 22 | mock.TestingT 23 | Cleanup(func()) 24 | } 25 | 26 | // NewBadgerOption creates a new instance of BadgerOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 27 | func NewBadgerOption(t mockConstructorTestingTNewBadgerOption) *BadgerOption { 28 | mock := &BadgerOption{} 29 | mock.Mock.Test(t) 30 | 31 | t.Cleanup(func() { mock.AssertExpectations(t) }) 32 | 33 | return mock 34 | } 35 | -------------------------------------------------------------------------------- /mocks/storage/database/commit_worker.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.13.1. DO NOT EDIT. 2 | 3 | package database 4 | 5 | import ( 6 | context "context" 7 | 8 | mock "github.com/stretchr/testify/mock" 9 | ) 10 | 11 | // CommitWorker is an autogenerated mock type for the CommitWorker type 12 | type CommitWorker struct { 13 | mock.Mock 14 | } 15 | 16 | // Execute provides a mock function with given fields: _a0 17 | func (_m *CommitWorker) Execute(_a0 context.Context) error { 18 | ret := _m.Called(_a0) 19 | 20 | var r0 error 21 | if rf, ok := ret.Get(0).(func(context.Context) error); ok { 22 | r0 = rf(_a0) 23 | } else { 24 | r0 = ret.Error(0) 25 | } 26 | 27 | return r0 28 | } 29 | 30 | type mockConstructorTestingTNewCommitWorker interface { 31 | mock.TestingT 32 | Cleanup(func()) 33 | } 34 | 35 | // NewCommitWorker creates a new instance of CommitWorker. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 36 | func NewCommitWorker(t mockConstructorTestingTNewCommitWorker) *CommitWorker { 37 | mock := &CommitWorker{} 38 | mock.Mock.Test(t) 39 | 40 | t.Cleanup(func() { mock.AssertExpectations(t) }) 41 | 42 | return mock 43 | } 44 | -------------------------------------------------------------------------------- /mocks/storage/modules/coin_storage_helper.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.13.1. DO NOT EDIT. 2 | 3 | package modules 4 | 5 | import ( 6 | context "context" 7 | 8 | mock "github.com/stretchr/testify/mock" 9 | 10 | database "github.com/coinbase/rosetta-sdk-go/storage/database" 11 | types "github.com/coinbase/rosetta-sdk-go/types" 12 | ) 13 | 14 | // CoinStorageHelper is an autogenerated mock type for the CoinStorageHelper type 15 | type CoinStorageHelper struct { 16 | mock.Mock 17 | } 18 | 19 | // CurrentBlockIdentifier provides a mock function with given fields: _a0, _a1 20 | func (_m *CoinStorageHelper) CurrentBlockIdentifier(_a0 context.Context, _a1 database.Transaction) (*types.BlockIdentifier, error) { 21 | ret := _m.Called(_a0, _a1) 22 | 23 | var r0 *types.BlockIdentifier 24 | if rf, ok := ret.Get(0).(func(context.Context, database.Transaction) *types.BlockIdentifier); ok { 25 | r0 = rf(_a0, _a1) 26 | } else { 27 | if ret.Get(0) != nil { 28 | r0 = ret.Get(0).(*types.BlockIdentifier) 29 | } 30 | } 31 | 32 | var r1 error 33 | if rf, ok := ret.Get(1).(func(context.Context, database.Transaction) error); ok { 34 | r1 = rf(_a0, _a1) 35 | } else { 36 | r1 = ret.Error(1) 37 | } 38 | 39 | return r0, r1 40 | } 41 | 42 | type mockConstructorTestingTNewCoinStorageHelper interface { 43 | mock.TestingT 44 | Cleanup(func()) 45 | } 46 | 47 | // NewCoinStorageHelper creates a new instance of CoinStorageHelper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 48 | func NewCoinStorageHelper(t mockConstructorTestingTNewCoinStorageHelper) *CoinStorageHelper { 49 | mock := &CoinStorageHelper{} 50 | mock.Mock.Test(t) 51 | 52 | t.Cleanup(func() { mock.AssertExpectations(t) }) 53 | 54 | return mock 55 | } 56 | -------------------------------------------------------------------------------- /mocks/syncer/handler.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.13.1. DO NOT EDIT. 2 | 3 | package syncer 4 | 5 | import ( 6 | context "context" 7 | 8 | mock "github.com/stretchr/testify/mock" 9 | 10 | types "github.com/coinbase/rosetta-sdk-go/types" 11 | ) 12 | 13 | // Handler is an autogenerated mock type for the Handler type 14 | type Handler struct { 15 | mock.Mock 16 | } 17 | 18 | // BlockAdded provides a mock function with given fields: ctx, block 19 | func (_m *Handler) BlockAdded(ctx context.Context, block *types.Block) error { 20 | ret := _m.Called(ctx, block) 21 | 22 | var r0 error 23 | if rf, ok := ret.Get(0).(func(context.Context, *types.Block) error); ok { 24 | r0 = rf(ctx, block) 25 | } else { 26 | r0 = ret.Error(0) 27 | } 28 | 29 | return r0 30 | } 31 | 32 | // BlockRemoved provides a mock function with given fields: ctx, block 33 | func (_m *Handler) BlockRemoved(ctx context.Context, block *types.BlockIdentifier) error { 34 | ret := _m.Called(ctx, block) 35 | 36 | var r0 error 37 | if rf, ok := ret.Get(0).(func(context.Context, *types.BlockIdentifier) error); ok { 38 | r0 = rf(ctx, block) 39 | } else { 40 | r0 = ret.Error(0) 41 | } 42 | 43 | return r0 44 | } 45 | 46 | // BlockSeen provides a mock function with given fields: ctx, block 47 | func (_m *Handler) BlockSeen(ctx context.Context, block *types.Block) error { 48 | ret := _m.Called(ctx, block) 49 | 50 | var r0 error 51 | if rf, ok := ret.Get(0).(func(context.Context, *types.Block) error); ok { 52 | r0 = rf(ctx, block) 53 | } else { 54 | r0 = ret.Error(0) 55 | } 56 | 57 | return r0 58 | } 59 | 60 | type mockConstructorTestingTNewHandler interface { 61 | mock.TestingT 62 | Cleanup(func()) 63 | } 64 | 65 | // NewHandler creates a new instance of Handler. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 66 | func NewHandler(t mockConstructorTestingTNewHandler) *Handler { 67 | mock := &Handler{} 68 | mock.Mock.Test(t) 69 | 70 | t.Cleanup(func() { mock.AssertExpectations(t) }) 71 | 72 | return mock 73 | } 74 | -------------------------------------------------------------------------------- /mocks/syncer/helper.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.13.1. DO NOT EDIT. 2 | 3 | package syncer 4 | 5 | import ( 6 | context "context" 7 | 8 | mock "github.com/stretchr/testify/mock" 9 | 10 | types "github.com/coinbase/rosetta-sdk-go/types" 11 | ) 12 | 13 | // Helper is an autogenerated mock type for the Helper type 14 | type Helper struct { 15 | mock.Mock 16 | } 17 | 18 | // Block provides a mock function with given fields: _a0, _a1, _a2 19 | func (_m *Helper) Block(_a0 context.Context, _a1 *types.NetworkIdentifier, _a2 *types.PartialBlockIdentifier) (*types.Block, error) { 20 | ret := _m.Called(_a0, _a1, _a2) 21 | 22 | var r0 *types.Block 23 | if rf, ok := ret.Get(0).(func(context.Context, *types.NetworkIdentifier, *types.PartialBlockIdentifier) *types.Block); ok { 24 | r0 = rf(_a0, _a1, _a2) 25 | } else { 26 | if ret.Get(0) != nil { 27 | r0 = ret.Get(0).(*types.Block) 28 | } 29 | } 30 | 31 | var r1 error 32 | if rf, ok := ret.Get(1).(func(context.Context, *types.NetworkIdentifier, *types.PartialBlockIdentifier) error); ok { 33 | r1 = rf(_a0, _a1, _a2) 34 | } else { 35 | r1 = ret.Error(1) 36 | } 37 | 38 | return r0, r1 39 | } 40 | 41 | // NetworkStatus provides a mock function with given fields: _a0, _a1 42 | func (_m *Helper) NetworkStatus(_a0 context.Context, _a1 *types.NetworkIdentifier) (*types.NetworkStatusResponse, error) { 43 | ret := _m.Called(_a0, _a1) 44 | 45 | var r0 *types.NetworkStatusResponse 46 | if rf, ok := ret.Get(0).(func(context.Context, *types.NetworkIdentifier) *types.NetworkStatusResponse); ok { 47 | r0 = rf(_a0, _a1) 48 | } else { 49 | if ret.Get(0) != nil { 50 | r0 = ret.Get(0).(*types.NetworkStatusResponse) 51 | } 52 | } 53 | 54 | var r1 error 55 | if rf, ok := ret.Get(1).(func(context.Context, *types.NetworkIdentifier) error); ok { 56 | r1 = rf(_a0, _a1) 57 | } else { 58 | r1 = ret.Error(1) 59 | } 60 | 61 | return r0, r1 62 | } 63 | 64 | type mockConstructorTestingTNewHelper interface { 65 | mock.TestingT 66 | Cleanup(func()) 67 | } 68 | 69 | // NewHelper creates a new instance of Helper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | func NewHelper(t mockConstructorTestingTNewHelper) *Helper { 71 | mock := &Helper{} 72 | mock.Mock.Test(t) 73 | 74 | t.Cleanup(func() { mock.AssertExpectations(t) }) 75 | 76 | return mock 77 | } 78 | -------------------------------------------------------------------------------- /mocks/utils/block_storage_helper.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.13.1. DO NOT EDIT. 2 | 3 | package utils 4 | 5 | import ( 6 | context "context" 7 | 8 | mock "github.com/stretchr/testify/mock" 9 | 10 | types "github.com/coinbase/rosetta-sdk-go/types" 11 | ) 12 | 13 | // BlockStorageHelper is an autogenerated mock type for the BlockStorageHelper type 14 | type BlockStorageHelper struct { 15 | mock.Mock 16 | } 17 | 18 | // GetBlockLazy provides a mock function with given fields: ctx, blockIdentifier 19 | func (_m *BlockStorageHelper) GetBlockLazy(ctx context.Context, blockIdentifier *types.PartialBlockIdentifier) (*types.BlockResponse, error) { 20 | ret := _m.Called(ctx, blockIdentifier) 21 | 22 | var r0 *types.BlockResponse 23 | if rf, ok := ret.Get(0).(func(context.Context, *types.PartialBlockIdentifier) *types.BlockResponse); ok { 24 | r0 = rf(ctx, blockIdentifier) 25 | } else { 26 | if ret.Get(0) != nil { 27 | r0 = ret.Get(0).(*types.BlockResponse) 28 | } 29 | } 30 | 31 | var r1 error 32 | if rf, ok := ret.Get(1).(func(context.Context, *types.PartialBlockIdentifier) error); ok { 33 | r1 = rf(ctx, blockIdentifier) 34 | } else { 35 | r1 = ret.Error(1) 36 | } 37 | 38 | return r0, r1 39 | } 40 | 41 | type mockConstructorTestingTNewBlockStorageHelper interface { 42 | mock.TestingT 43 | Cleanup(func()) 44 | } 45 | 46 | // NewBlockStorageHelper creates a new instance of BlockStorageHelper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 47 | func NewBlockStorageHelper(t mockConstructorTestingTNewBlockStorageHelper) *BlockStorageHelper { 48 | mock := &BlockStorageHelper{} 49 | mock.Mock.Test(t) 50 | 51 | t.Cleanup(func() { mock.AssertExpectations(t) }) 52 | 53 | return mock 54 | } 55 | -------------------------------------------------------------------------------- /parser/README.md: -------------------------------------------------------------------------------- 1 | # Parser 2 | 3 | [![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/parser?tab=doc) 4 | 5 | The Parser package provides support for parsing Mesh blocks. This includes 6 | things like calculating all the balance changes that occurred in a block and 7 | grouping related operations. 8 | 9 | ## Installation 10 | 11 | ```shell 12 | go get github.com/coinbase/mesh-sdk-go/parser 13 | ``` 14 | -------------------------------------------------------------------------------- /parser/errors_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package parser 16 | 17 | import ( 18 | "testing" 19 | 20 | "github.com/stretchr/testify/assert" 21 | ) 22 | 23 | func TestErr(t *testing.T) { 24 | var tests = map[string]struct { 25 | err error 26 | is bool 27 | source string 28 | }{ 29 | "intent error": { 30 | err: ErrExpectedOperationAccountMismatch, 31 | is: true, 32 | source: "intent error", 33 | }, 34 | "match operations error": { 35 | err: ErrAccountMatchAccountMissing, 36 | is: true, 37 | source: "match operations error", 38 | }, 39 | } 40 | 41 | for name, test := range tests { 42 | t.Run(name, func(t *testing.T) { 43 | is, source := Err(test.err) 44 | assert.Equal(t, test.is, is) 45 | assert.Equal(t, test.source, source) 46 | }) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /parser/exemptions.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package parser 16 | 17 | import ( 18 | "math/big" 19 | 20 | "github.com/coinbase/rosetta-sdk-go/types" 21 | ) 22 | 23 | // FindExemptions returns all matching *types.BalanceExemption 24 | // for a particular *types.AccountIdentifier and *types.Currency. 25 | func (p *Parser) FindExemptions( 26 | account *types.AccountIdentifier, 27 | currency *types.Currency, 28 | ) []*types.BalanceExemption { 29 | matches := []*types.BalanceExemption{} 30 | for _, exemption := range p.BalanceExemptions { 31 | if exemption.Currency != nil && types.Hash(currency) != types.Hash(exemption.Currency) { 32 | continue 33 | } 34 | 35 | if exemption.SubAccountAddress != nil && 36 | (account.SubAccount == nil || *exemption.SubAccountAddress != account.SubAccount.Address) { 37 | continue 38 | } 39 | 40 | matches = append(matches, exemption) 41 | } 42 | 43 | return matches 44 | } 45 | 46 | // MatchBalanceExemption returns a *types.BalanceExemption 47 | // associated with the *types.AccountIdentifier, *types.Currency, 48 | // and difference, if it exists. The provided exemptions 49 | // should be produced using FindExemptions. 50 | func MatchBalanceExemption( 51 | matchedExemptions []*types.BalanceExemption, 52 | difference string, // live - computed 53 | ) *types.BalanceExemption { 54 | bigDifference, ok := new(big.Int).SetString(difference, 10) // nolint 55 | if !ok { 56 | return nil 57 | } 58 | 59 | for _, exemption := range matchedExemptions { 60 | if exemption.ExemptionType == types.BalanceDynamic || 61 | (exemption.ExemptionType == types.BalanceGreaterOrEqual && bigDifference.Sign() >= 0) || 62 | (exemption.ExemptionType == types.BalanceLessOrEqual && bigDifference.Sign() <= 0) { 63 | return exemption 64 | } 65 | } 66 | 67 | return nil 68 | } 69 | -------------------------------------------------------------------------------- /parser/parser.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package parser 16 | 17 | import ( 18 | "github.com/coinbase/rosetta-sdk-go/asserter" 19 | "github.com/coinbase/rosetta-sdk-go/types" 20 | ) 21 | 22 | // Parser provides support for parsing Rosetta blocks. 23 | type Parser struct { 24 | Asserter *asserter.Asserter 25 | ExemptFunc ExemptOperation 26 | BalanceExemptions []*types.BalanceExemption 27 | } 28 | 29 | // New creates a new Parser. 30 | func New( 31 | asserter *asserter.Asserter, 32 | exemptFunc ExemptOperation, 33 | balanceExemptions []*types.BalanceExemption, 34 | ) *Parser { 35 | return &Parser{ 36 | Asserter: asserter, 37 | ExemptFunc: exemptFunc, 38 | BalanceExemptions: balanceExemptions, 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /reconciler/README.md: -------------------------------------------------------------------------------- 1 | # Reconciler 2 | 3 | [![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/reconciler?tab=doc) 4 | 5 | The Reconciler package is used to ensure that balance changes derived from 6 | parsing Mesh blocks are equivalent to the balance changes computed by the 7 | node. If you want to see an example of how to use this package, take 8 | a look at [mesh-cli](https://github.com/coinbase/mesh-cli). 9 | 10 | ## Features 11 | * Customizable `Helper` and `Handler` to define your own logic for retrieving 12 | calculated balance changes and handling successful/unsuccessful comparisons 13 | * Perform balance lookup at either historical blocks or the current block (if 14 | historical balance query is not supported) 15 | * Provide a list of accounts to compare at each block (for quick and easy 16 | debugging) 17 | 18 | ## Installation 19 | 20 | ```shell 21 | go get github.com/coinbase/mesh-sdk-go/reconciler 22 | ``` 23 | 24 | ## Reconciliation Strategies 25 | ### Active Addresses 26 | The reconciler checks that the balance of an account computed by 27 | its operations is equal to the balance of the account according 28 | to the node. If this balance is not identical, the reconciler will 29 | error. 30 | 31 | ### Inactive Addresses 32 | The reconciler randomly checks the balances of accounts that aren't 33 | involved in any transactions. The balances of accounts could change 34 | on the blockchain node without being included in an operation 35 | returned by the Mesh Data API. Recall that all balance-changing 36 | operations must be returned by the Mesh Data API. 37 | -------------------------------------------------------------------------------- /reconciler/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package reconciler 16 | 17 | import ( 18 | "errors" 19 | 20 | utils "github.com/coinbase/rosetta-sdk-go/errors" 21 | ) 22 | 23 | // Named error types for Reconciler errors 24 | var ( 25 | // ErrHeadBlockBehindLive is returned when the processed 26 | // head is behind the live head. Sometimes, it is 27 | // preferable to sleep and wait to catch up when 28 | // we are close to the live head (waitToCheckDiff). 29 | ErrHeadBlockBehindLive = errors.New("head block behind") 30 | 31 | // ErrBlockGone is returned when the processed block 32 | // head is greater than the live head but the block 33 | // does not exist in the store. This likely means 34 | // that the block was orphaned. 35 | ErrBlockGone = errors.New("block gone") 36 | ) 37 | 38 | // Err takes an error as an argument and returns 39 | // whether or not the error is one thrown by the reconciler package 40 | func Err(err error) bool { 41 | reconcilerErrors := []error{ 42 | ErrHeadBlockBehindLive, 43 | ErrBlockGone, 44 | } 45 | 46 | return utils.FindError(reconcilerErrors, err) 47 | } 48 | -------------------------------------------------------------------------------- /reconciler/errors_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package reconciler 16 | 17 | import ( 18 | "errors" 19 | "testing" 20 | 21 | "github.com/stretchr/testify/assert" 22 | ) 23 | 24 | func TestErr(t *testing.T) { 25 | var tests = map[string]struct { 26 | err error 27 | is bool 28 | }{ 29 | "is a reconciler error": { 30 | err: ErrHeadBlockBehindLive, 31 | is: true, 32 | }, 33 | "not a reconciler error": { 34 | err: errors.New("blah"), 35 | is: false, 36 | }, 37 | } 38 | 39 | for name, test := range tests { 40 | t.Run(name, func(t *testing.T) { 41 | is := Err(test.err) 42 | assert.Equal(t, test.is, is) 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /server/README.md: -------------------------------------------------------------------------------- 1 | # Server 2 | 3 | [![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/server?tab=doc) 4 | 5 | The Server package reduces the work required to write your own Mesh server. 6 | In short, this package takes care of the basics (boilerplate server code 7 | and request validation) so that you can focus on code that is unique to your 8 | implementation. 9 | 10 | ## Installation 11 | 12 | ```shell 13 | go get github.com/coinbase/mesh-sdk-go/server 14 | ``` 15 | 16 | ## Components 17 | ### Router 18 | The router is a [Mux](https://github.com/gorilla/mux) router that 19 | routes traffic to the correct controller. 20 | 21 | ### Controller 22 | Controllers are automatically generated code that specify an interface 23 | that a service must implement. 24 | 25 | ### Services 26 | Services are implemented by you to populate responses. These services 27 | are invoked by controllers. 28 | 29 | ## Recommended Folder Structure 30 | ``` 31 | main.go 32 | /services 33 | block_service.go 34 | network_service.go 35 | ... 36 | ``` 37 | 38 | ## Examples 39 | Check out the [examples](/examples) to see how easy 40 | it is to create your own server. 41 | -------------------------------------------------------------------------------- /server/logger.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package server 18 | 19 | import ( 20 | "log" 21 | "net/http" 22 | "time" 23 | ) 24 | 25 | // LoggerMiddleware is a simple logger middleware that prints the requests in 26 | // an ad-hoc fashion to the stdlib's log. 27 | func LoggerMiddleware(inner http.Handler) http.Handler { 28 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 29 | start := time.Now() 30 | 31 | inner.ServeHTTP(w, r) 32 | 33 | log.Printf( 34 | "%s %s %s", 35 | r.Method, 36 | r.RequestURI, 37 | time.Since(start), 38 | ) 39 | }) 40 | } 41 | -------------------------------------------------------------------------------- /storage/encoder/buffer_pool.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package encoder 16 | 17 | import ( 18 | "bytes" 19 | "sync" 20 | ) 21 | 22 | // BufferPool contains a sync.Pool 23 | // of *bytes.Buffer. 24 | type BufferPool struct { 25 | pool sync.Pool 26 | } 27 | 28 | // NewBufferPool returns a new *BufferPool. 29 | func NewBufferPool() *BufferPool { 30 | return &BufferPool{ 31 | pool: sync.Pool{ 32 | New: func() interface{} { 33 | return new(bytes.Buffer) 34 | }, 35 | }, 36 | } 37 | } 38 | 39 | // Put resets the provided *bytes.Buffer and stores 40 | // it in the pool for reuse. 41 | func (p *BufferPool) Put(buffer *bytes.Buffer) { 42 | buffer.Reset() 43 | p.pool.Put(buffer) 44 | } 45 | 46 | // PutByteSlice creates a *bytes.Buffer from the provided 47 | // []byte and stores it in the pool for reuse. 48 | func (p *BufferPool) PutByteSlice(buffer []byte) { 49 | p.Put(bytes.NewBuffer(buffer)) 50 | } 51 | 52 | // Get returns a new or reused *bytes.Buffer. 53 | func (p *BufferPool) Get() *bytes.Buffer { 54 | return p.pool.Get().(*bytes.Buffer) 55 | } 56 | -------------------------------------------------------------------------------- /storage/errors/errors_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package errors 16 | 17 | import ( 18 | "errors" 19 | "testing" 20 | 21 | "github.com/stretchr/testify/assert" 22 | ) 23 | 24 | func TestErr(t *testing.T) { 25 | var tests = map[string]struct { 26 | err error 27 | is bool 28 | source string 29 | }{ 30 | "balance storage error": { 31 | err: ErrNegativeBalance, 32 | is: true, 33 | source: "balance storage error", 34 | }, 35 | "block storage error": { 36 | err: ErrHeadBlockNotFound, 37 | is: true, 38 | source: "block storage error", 39 | }, 40 | "key storage error": { 41 | err: ErrAddrExists, 42 | is: true, 43 | source: "key storage error", 44 | }, 45 | "not a storage error": { 46 | err: errors.New("blah"), 47 | is: false, 48 | source: "", 49 | }, 50 | } 51 | 52 | for name, test := range tests { 53 | t.Run(name, func(t *testing.T) { 54 | is, source := Err(test.err) 55 | assert.Equal(t, test.is, is) 56 | assert.Equal(t, test.source, source) 57 | }) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /storage/modules/counter_storage_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package modules 16 | 17 | import ( 18 | "context" 19 | "math/big" 20 | "testing" 21 | 22 | "github.com/stretchr/testify/assert" 23 | 24 | "github.com/coinbase/rosetta-sdk-go/utils" 25 | ) 26 | 27 | func TestCounterStorage(t *testing.T) { 28 | ctx := context.Background() 29 | 30 | newDir, err := utils.CreateTempDir() 31 | assert.NoError(t, err) 32 | defer utils.RemoveTempDir(newDir) 33 | 34 | database, err := newTestBadgerDatabase(ctx, newDir) 35 | assert.NoError(t, err) 36 | defer database.Close(ctx) 37 | 38 | c := NewCounterStorage(database) 39 | 40 | t.Run("get unset counter", func(t *testing.T) { 41 | v, err := c.Get(ctx, "blah") 42 | assert.NoError(t, err) 43 | assert.Equal(t, v, big.NewInt(0)) 44 | }) 45 | 46 | t.Run("increase counter", func(t *testing.T) { 47 | v, err := c.Update(ctx, "blah", big.NewInt(100)) 48 | assert.NoError(t, err) 49 | assert.Equal(t, v, big.NewInt(100)) 50 | 51 | v, err = c.Get(ctx, "blah") 52 | assert.NoError(t, err) 53 | assert.Equal(t, v, big.NewInt(100)) 54 | }) 55 | 56 | t.Run("decrement counter", func(t *testing.T) { 57 | v, err := c.Update(ctx, "blah", big.NewInt(-50)) 58 | assert.NoError(t, err) 59 | assert.Equal(t, v, big.NewInt(50)) 60 | 61 | v, err = c.Get(ctx, "blah") 62 | assert.NoError(t, err) 63 | assert.Equal(t, v, big.NewInt(50)) 64 | }) 65 | 66 | t.Run("get unset counter after update", func(t *testing.T) { 67 | v, err := c.Get(ctx, "blah2") 68 | assert.NoError(t, err) 69 | assert.Equal(t, v, big.NewInt(0)) 70 | }) 71 | } 72 | -------------------------------------------------------------------------------- /storage/modules/utils.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package modules 16 | 17 | import ( 18 | "context" 19 | "fmt" 20 | 21 | "github.com/coinbase/rosetta-sdk-go/storage/database" 22 | "github.com/coinbase/rosetta-sdk-go/storage/errors" 23 | ) 24 | 25 | func storeUniqueKey( 26 | ctx context.Context, 27 | transaction database.Transaction, 28 | key []byte, 29 | value []byte, 30 | reclaimValue bool, 31 | ) error { 32 | exists, _, err := transaction.Get(ctx, key) 33 | if err != nil { 34 | return err 35 | } 36 | 37 | if exists { 38 | return fmt.Errorf( 39 | "key %s is invalid: %w", 40 | string(key), 41 | errors.ErrDuplicateKey, 42 | ) 43 | } 44 | 45 | return transaction.Set(ctx, key, value, reclaimValue) 46 | } 47 | 48 | // newTestBadgerDatabase creates a new Badger Database at the following directory. This is 49 | // used extensively in module tests. 50 | func newTestBadgerDatabase(ctx context.Context, dir string) (database.Database, error) { 51 | return database.NewBadgerDatabase( 52 | ctx, 53 | dir, 54 | database.WithIndexCacheSize(database.TinyIndexCacheSize), 55 | ) 56 | } 57 | -------------------------------------------------------------------------------- /syncer/README.md: -------------------------------------------------------------------------------- 1 | # Syncer 2 | 3 | [![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/syncer?tab=doc) 4 | 5 | The Syncer package provides support for syncing blocks from any Mesh Data API 6 | implementation. If you want to see an example of how to use this package, take 7 | a look at [mesh-cli](https://github.com/coinbase/mesh-cli). 8 | 9 | ## Features 10 | * Automatic handling of block re-orgs 11 | * Multi-threaded block fetching (using the `fetcher` package) 12 | * Implementable `Handler` to define your own block processing logic (ex: store 13 | processed blocks to a db or print our balance changes) 14 | 15 | ## Installation 16 | 17 | ```shell 18 | go get github.com/coinbase/mesh-sdk-go/syncer 19 | ``` 20 | 21 | ## Future Work 22 | * Sync multiple shards in a sharded blockchain 23 | -------------------------------------------------------------------------------- /syncer/configuration.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package syncer 16 | 17 | import ( 18 | "github.com/coinbase/rosetta-sdk-go/types" 19 | ) 20 | 21 | // Option is used to overwrite default values in 22 | // Syncer construction. Any Option not provided 23 | // falls back to the default value. 24 | type Option func(s *Syncer) 25 | 26 | // WithCacheSize overrides the default cache size. 27 | func WithCacheSize(cacheSize int) Option { 28 | return func(s *Syncer) { 29 | s.cacheSize = cacheSize 30 | } 31 | } 32 | 33 | // WithSizeMultiplier overrides the default size multiplier. 34 | func WithSizeMultiplier(sizeMultiplier float64) Option { 35 | return func(s *Syncer) { 36 | s.sizeMultiplier = sizeMultiplier 37 | } 38 | } 39 | 40 | // WithPastBlocks provides the syncer with a cache 41 | // of previously processed blocks to handle reorgs. 42 | func WithPastBlocks(blocks []*types.BlockIdentifier) Option { 43 | return func(s *Syncer) { 44 | s.pastBlocks = blocks 45 | } 46 | } 47 | 48 | // WithPastBlockLimit overrides the default past block limit 49 | func WithPastBlockLimit(blocks int) Option { 50 | return func(s *Syncer) { 51 | s.pastBlockLimit = blocks 52 | } 53 | } 54 | 55 | // WithMaxConcurrency overrides the default max concurrency. 56 | func WithMaxConcurrency(concurrency int64) Option { 57 | return func(s *Syncer) { 58 | s.maxConcurrency = concurrency 59 | } 60 | } 61 | 62 | // WithAdjustmentWindow overrides the default adjustment window. 63 | func WithAdjustmentWindow(adjustmentWindow int64) Option { 64 | return func(s *Syncer) { 65 | s.adjustmentWindow = adjustmentWindow 66 | } 67 | } 68 | 69 | // add a info map to Syncer 70 | func WithMetaData(metaData string) Option { 71 | return func(s *Syncer) { 72 | s.metaData = metaData 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /syncer/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package syncer 16 | 17 | import ( 18 | "errors" 19 | 20 | utils "github.com/coinbase/rosetta-sdk-go/errors" 21 | ) 22 | 23 | // Named error types for Syncer errors 24 | var ( 25 | // ErrCannotRemoveGenesisBlock is returned by the syncer when 26 | // a Rosetta implementation indicates that the 27 | // genesis block should be orphaned. 28 | ErrCannotRemoveGenesisBlock = errors.New("cannot remove genesis block") 29 | 30 | // ErrOrphanHead is returned by the Helper when 31 | // the current head should be orphaned. In some 32 | // cases, it may not be possible to populate a block 33 | // if the head of the canonical chain is not yet synced. 34 | ErrOrphanHead = errors.New("orphan head") 35 | 36 | // ErrBlockResultNil is returned by the syncer 37 | // when attempting to process a block and the block 38 | // result is nil. 39 | ErrBlockResultNil = errors.New("block result is nil") 40 | 41 | // ErrGetCurrentHeadBlockFailed is returned by the syncer when 42 | // the current head block index is not able to get 43 | ErrGetCurrentHeadBlockFailed = errors.New("unable to get current head block index") 44 | 45 | // ErrOutOfOrder is returned when the syncer examines 46 | // a block that is out of order. This typically 47 | // means the Helper has a bug. 48 | ErrOutOfOrder = errors.New("block processing is out of order") 49 | ) 50 | 51 | // Err takes an error as an argument and returns 52 | // whether or not the error is one thrown by the syncer package 53 | func Err(err error) bool { 54 | syncerErrors := []error{ 55 | ErrCannotRemoveGenesisBlock, 56 | ErrOrphanHead, 57 | ErrBlockResultNil, 58 | ErrGetCurrentHeadBlockFailed, 59 | ErrOutOfOrder, 60 | } 61 | 62 | return utils.FindError(syncerErrors, err) 63 | } 64 | -------------------------------------------------------------------------------- /syncer/errors_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package syncer 16 | 17 | import ( 18 | "errors" 19 | "testing" 20 | 21 | "github.com/stretchr/testify/assert" 22 | ) 23 | 24 | func TestErr(t *testing.T) { 25 | var tests = map[string]struct { 26 | err error 27 | is bool 28 | }{ 29 | "is a keys error": { 30 | err: ErrCannotRemoveGenesisBlock, 31 | is: true, 32 | }, 33 | "not a keys error": { 34 | err: errors.New("blah"), 35 | is: false, 36 | }, 37 | } 38 | 39 | for name, test := range tests { 40 | t.Run(name, func(t *testing.T) { 41 | is := Err(test.err) 42 | assert.Equal(t, test.is, is) 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /templates/client/model.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | package {{packageName}} 3 | {{#models}} 4 | {{#model}} 5 | {{#isEnum}} 6 | // {{{classname}}} {{#description}}{{{.}}}{{/description}}{{^description}}the model '{{{classname}}}'{{/description}} 7 | type {{{classname}}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{/format}} 8 | 9 | // List of {{{name}}} 10 | const ( 11 | {{#allowableValues}} 12 | {{#enumVars}} 13 | {{^-first}} 14 | {{/-first}} 15 | {{#enumClassPrefix}}{{{classname.toUpperCase}}}_{{/enumClassPrefix}}{{name}} {{{classname}}} = {{{value}}} 16 | {{/enumVars}} 17 | {{/allowableValues}} 18 | ) 19 | {{/isEnum}} 20 | {{^isEnum}} 21 | // {{classname}}{{#description}} {{{description}}}{{/description}}{{^description}} struct for {{{classname}}}{{/description}} 22 | type {{classname}} struct { 23 | {{#allVars}} 24 | {{^-first}} 25 | {{/-first}} 26 | {{#description}} 27 | // {{{description}}} 28 | {{/description}} 29 | {{name}} {{^isPrimitiveType}}{{#required}}*{{/required}}{{/isPrimitiveType}}{{^required}}*{{/required}}{{{dataType}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"` 30 | {{/allVars}} 31 | } 32 | {{/isEnum}} 33 | {{/model}} 34 | {{/models}} 35 | -------------------------------------------------------------------------------- /templates/client/partial_header.mustache: -------------------------------------------------------------------------------- 1 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 2 | -------------------------------------------------------------------------------- /templates/client/response.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | package {{packageName}} 3 | 4 | import ( 5 | "net/http" 6 | ) 7 | 8 | // APIResponse stores the API response returned by the server. 9 | type APIResponse struct { 10 | *http.Response `json:"-"` 11 | Message string `json:"message,omitempty"` 12 | // Operation is the name of the OpenAPI operation. 13 | Operation string `json:"operation,omitempty"` 14 | // RequestURL is the request URL. This value is always available, even if the 15 | // embedded *http.Response is nil. 16 | RequestURL string `json:"url,omitempty"` 17 | // Method is the HTTP method used for the request. This value is always 18 | // available, even if the embedded *http.Response is nil. 19 | Method string `json:"method,omitempty"` 20 | // Payload holds the contents of the response body (which may be nil or empty). 21 | // This is provided here as the raw response.Body() reader will have already 22 | // been drained. 23 | Payload []byte `json:"-"` 24 | } 25 | 26 | // NewAPIResponse returns a new APIResonse object. 27 | func NewAPIResponse(r *http.Response) *APIResponse { 28 | response := &APIResponse{Response: r} 29 | return response 30 | } 31 | 32 | // NewAPIResponseWithError returns a new APIResponse object with the provided error message. 33 | func NewAPIResponseWithError(errorMessage string) *APIResponse { 34 | response := &APIResponse{Message: errorMessage} 35 | return response 36 | } 37 | -------------------------------------------------------------------------------- /templates/docs/client.md: -------------------------------------------------------------------------------- 1 | # Client 2 | 3 | [![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/client?tab=doc) 4 | 5 | The Client package reduces the work required to communicate with a Mesh server. 6 | 7 | If you want a higher-level interface that automatically asserts that server responses 8 | are correct, check out the [Fetcher](/fetcher). 9 | 10 | ## Installation 11 | 12 | ```shell 13 | go get github.com/coinbase/mesh-sdk-go/client 14 | ``` 15 | 16 | ## Examples 17 | Check out the [examples](/examples) to see how easy 18 | it is to connect to a Mesh server. 19 | -------------------------------------------------------------------------------- /templates/docs/server.md: -------------------------------------------------------------------------------- 1 | # Server 2 | 3 | The Server package reduces the work required to write your own Mesh server. 4 | In short, this package takes care of the basics (boilerplate server code 5 | and request validation) so that you can focus on code that is unique to your 6 | implementation. 7 | 8 | ## Installation 9 | 10 | ```shell 11 | go get github.com/coinbase/mesh-sdk-go/server 12 | ``` 13 | 14 | ## Components 15 | ### Router 16 | The router is a [Mux](https://github.com/gorilla/mux) router that 17 | routes traffic to the correct controller. 18 | 19 | ### Controller 20 | Contollers are automatically generated code that specify an interface 21 | that a service must implement. 22 | 23 | ### Services 24 | Services are implemented by you to populate responses. These services 25 | are invoked by controllers. 26 | 27 | ## Recommended Folder Structure 28 | ``` 29 | main.go 30 | /services 31 | block_service.go 32 | network_service.go 33 | ... 34 | ``` 35 | 36 | ## Examples 37 | Check out the [examples](/examples) to see how easy 38 | it is to create your own server. 39 | -------------------------------------------------------------------------------- /templates/docs/types.md: -------------------------------------------------------------------------------- 1 | # Types 2 | 3 | [![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/types?tab=doc) 4 | 5 | Types contains a collection of auto-generated Mesh types. Using this 6 | package ensures that you don't need to automatically generate code on your 7 | own. 8 | 9 | ## Installation 10 | 11 | ```shell 12 | go get github.com/coinbase/mesh-sdk-go/types 13 | ``` 14 | -------------------------------------------------------------------------------- /templates/go.mod.types: -------------------------------------------------------------------------------- 1 | module github.com/coinbase/rosetta-sdk-go/types 2 | 3 | go 1.19 4 | -------------------------------------------------------------------------------- /templates/marshal.txt: -------------------------------------------------------------------------------- 1 | 2 | // MarshalJSON overrides the default JSON marshaler 3 | // and encodes bytes as hex instead of base64. 4 | func (s *STRUCT_NAME) MarshalJSON() ([]byte, error) { 5 | type Alias STRUCT_NAME 6 | j, err := json.Marshal(struct { 7 | Bytes string `json:"hex_bytes"` 8 | *Alias 9 | }{ 10 | Bytes: hex.EncodeToString(s.Bytes), 11 | Alias: (*Alias)(s), 12 | }) 13 | if err != nil { 14 | return nil, err 15 | } 16 | return j, nil 17 | } 18 | 19 | // UnmarshalJSON overrides the default JSON unmarshaler 20 | // and decodes bytes from hex instead of base64. 21 | func (s *STRUCT_NAME) UnmarshalJSON(b []byte) error { 22 | type Alias STRUCT_NAME 23 | r := struct { 24 | Bytes string `json:"hex_bytes"` 25 | *Alias 26 | }{ 27 | Alias: (*Alias)(s), 28 | } 29 | err := json.Unmarshal(b, &r) 30 | if err != nil { 31 | return err 32 | } 33 | 34 | bytes, err := hex.DecodeString(r.Bytes) 35 | if err != nil { 36 | return err 37 | } 38 | 39 | s.Bytes = bytes 40 | return nil 41 | } 42 | -------------------------------------------------------------------------------- /templates/server/api.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | package {{packageName}} 3 | 4 | import ( 5 | "context" 6 | "net/http" 7 | 8 | "github.com/coinbase/rosetta-sdk-go/types" 9 | ) 10 | 11 | {{#apiInfo}}{{#apis}} 12 | // {{classname}}Router defines the required methods for binding the api requests to a responses for the {{classname}} 13 | // The {{classname}}Router implementation should parse necessary information from the http request, 14 | // pass the data to a {{classname}}Servicer to perform the required actions, then write the service results to the http response. 15 | type {{classname}}Router interface { {{#operations}}{{#operation}} 16 | {{operationId}}(http.ResponseWriter, *http.Request){{/operation}}{{/operations}} 17 | }{{/apis}}{{/apiInfo}}{{#apiInfo}}{{#apis}} 18 | 19 | 20 | // {{classname}}Servicer defines the api actions for the {{classname}} service 21 | // This interface intended to stay up to date with the openapi yaml used to generate it, 22 | // while the service implementation can ignored with the .openapi-generator-ignore file 23 | // and updated with the logic required for the API. 24 | type {{classname}}Servicer interface { {{#operations}}{{#operation}} 25 | {{operationId}}(context.Context, {{#allParams}}*types.{{dataType}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) (*types.{{returnType}}, *types.Error){{/operation}}{{/operations}} 26 | }{{/apis}}{{/apiInfo}} 27 | -------------------------------------------------------------------------------- /templates/server/controller-api.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | package {{packageName}} 3 | 4 | import ( 5 | "encoding/json" 6 | "net/http" 7 | "strings" 8 | 9 | "github.com/coinbase/rosetta-sdk-go/types" 10 | "github.com/coinbase/rosetta-sdk-go/asserter" 11 | ) 12 | 13 | // A {{classname}}Controller binds http requests to an api service and writes the service results to the http response 14 | type {{classname}}Controller struct { 15 | service {{classname}}Servicer 16 | asserter *asserter.Asserter 17 | } 18 | 19 | // New{{classname}}Controller creates a default api controller 20 | func New{{classname}}Controller( 21 | s {{classname}}Servicer, 22 | asserter *asserter.Asserter, 23 | ) Router { 24 | return &{{classname}}Controller{ 25 | service: s, 26 | asserter: asserter, 27 | } 28 | } 29 | 30 | // Routes returns all of the api route for the {{classname}}Controller 31 | func (c *{{classname}}Controller) Routes() Routes { 32 | return Routes{ {{#operations}}{{#operation}} 33 | { 34 | "{{operationId}}", 35 | strings.ToUpper("{{httpMethod}}"), 36 | "{{{basePathWithoutHost}}}{{{path}}}", 37 | c.{{operationId}}, 38 | },{{/operation}}{{/operations}} 39 | } 40 | }{{#operations}}{{#operation}} 41 | 42 | // {{nickname}} - {{{summary}}} 43 | func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Request) { {{#allParams}}{{#isHeaderParam}} 44 | {{paramName}} := r.Header.Get("{{paramName}}"){{/isHeaderParam}}{{#isBodyParam}} 45 | {{paramName}} := &types.{{dataType}}{} 46 | if err := json.NewDecoder(r.Body).Decode(&{{paramName}}); err != nil { 47 | EncodeJSONResponse(&types.Error{ 48 | Message: err.Error(), 49 | }, http.StatusInternalServerError, w) 50 | 51 | return 52 | } 53 | 54 | // Assert that {{dataType}} is correct 55 | if err := c.asserter.{{dataType}}({{paramName}}); err != nil { 56 | EncodeJSONResponse(&types.Error{ 57 | Message: err.Error(), 58 | }, http.StatusInternalServerError, w) 59 | 60 | return 61 | } 62 | 63 | {{/isBodyParam}}{{/allParams}} 64 | result, serviceErr := c.service.{{nickname}}(r.Context(), {{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) 65 | if serviceErr != nil { 66 | EncodeJSONResponse(serviceErr, http.StatusInternalServerError, w) 67 | 68 | return 69 | } 70 | 71 | EncodeJSONResponse(result, http.StatusOK, w) 72 | }{{/operation}}{{/operations}} 73 | -------------------------------------------------------------------------------- /templates/server/logger.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | package {{packageName}} 3 | 4 | import ( 5 | "log" 6 | "net/http" 7 | "time" 8 | ) 9 | 10 | // LoggerMiddleware is a simple logger middleware that prints the requests in 11 | // an ad-hoc fashion to the stdlib's log. 12 | func LoggerMiddleware(inner http.Handler) http.Handler { 13 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 14 | start := time.Now() 15 | 16 | inner.ServeHTTP(w, r) 17 | 18 | log.Printf( 19 | "%s %s %s", 20 | r.Method, 21 | r.RequestURI, 22 | time.Since(start), 23 | ) 24 | }) 25 | } 26 | -------------------------------------------------------------------------------- /templates/server/partial_header.mustache: -------------------------------------------------------------------------------- 1 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 2 | -------------------------------------------------------------------------------- /templates/server/routers.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | package {{packageName}} 3 | 4 | import ( 5 | "encoding/json" 6 | "net/http" 7 | 8 | "github.com/gorilla/mux" 9 | ) 10 | 11 | // A Route defines the parameters for an api endpoint 12 | type Route struct { 13 | Name string 14 | Method string 15 | Pattern string 16 | HandlerFunc http.HandlerFunc 17 | } 18 | 19 | // Routes are a collection of defined api endpoints 20 | type Routes []Route 21 | 22 | // Router defines the required methods for retrieving api routes 23 | type Router interface { 24 | Routes() Routes 25 | } 26 | 27 | // CorsMiddleware handles CORS and ensures OPTIONS requests are 28 | // handled properly. 29 | // 30 | // This may be used to expose a Rosetta server instance to requests made by web 31 | // apps served over a different domain. Note that his currently allows _all_ 32 | // third party domains so callers might want to adapt this middleware for their 33 | // own use-cases. 34 | func CorsMiddleware(next http.Handler) http.Handler { 35 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 36 | w.Header().Set("Access-Control-Allow-Origin", "*") 37 | w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept") 38 | w.Header().Set("Access-Control-Allow-Methods", "GET, POST,OPTIONS") 39 | if r.Method == "OPTIONS" { 40 | w.WriteHeader(http.StatusOK) 41 | return 42 | } 43 | next.ServeHTTP(w, r) 44 | }) 45 | } 46 | 47 | // NewRouter creates a new router for any number of api routers 48 | func NewRouter(routers ...Router) http.Handler { 49 | router := mux.NewRouter().StrictSlash(true) 50 | for _, api := range routers { 51 | for _, route := range api.Routes() { 52 | router. 53 | Methods(route.Method). 54 | Path(route.Pattern). 55 | Name(route.Name). 56 | Handler(route.HandlerFunc) 57 | } 58 | } 59 | 60 | return router 61 | } 62 | 63 | // EncodeJSONResponse uses the json encoder to write an interface to the http response with an optional status code 64 | func EncodeJSONResponse(i interface{}, status int, w http.ResponseWriter) { 65 | w.Header().Set("Content-Type", "application/json; charset=UTF-8") 66 | w.WriteHeader(status) 67 | 68 | if err := json.NewEncoder(w).Encode(i); err != nil { 69 | http.Error(w, err.Error(), http.StatusInternalServerError) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /templates/types.txt: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | const ( 4 | // RosettaAPIVersion is the version of the Rosetta API 5 | // specification used to generate code for this release 6 | // of the SDK. 7 | RosettaAPIVersion = "VERSION" 8 | ) 9 | -------------------------------------------------------------------------------- /types/README.md: -------------------------------------------------------------------------------- 1 | # Types 2 | 3 | [![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/types?tab=doc) 4 | 5 | Types contains a collection of auto-generated Mesh types. Using this 6 | package ensures that you don't need to automatically generate code on your 7 | own. 8 | 9 | ## Installation 10 | 11 | ```shell 12 | go get github.com/coinbase/mesh-sdk-go/types 13 | ``` 14 | -------------------------------------------------------------------------------- /types/account_balance_request.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // AccountBalanceRequest An AccountBalanceRequest is utilized to make a balance request on the 20 | // /account/balance endpoint. If the block_identifier is populated, a historical balance query 21 | // should be performed. 22 | type AccountBalanceRequest struct { 23 | NetworkIdentifier *NetworkIdentifier `json:"network_identifier"` 24 | AccountIdentifier *AccountIdentifier `json:"account_identifier"` 25 | BlockIdentifier *PartialBlockIdentifier `json:"block_identifier,omitempty"` 26 | // In some cases, the caller may not want to retrieve all available balances for an 27 | // AccountIdentifier. If the currencies field is populated, only balances for the specified 28 | // currencies will be returned. If not populated, all available balances will be returned. 29 | Currencies []*Currency `json:"currencies,omitempty"` 30 | } 31 | -------------------------------------------------------------------------------- /types/account_balance_response.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // AccountBalanceResponse An AccountBalanceResponse is returned on the /account/balance endpoint. If 20 | // an account has a balance for each AccountIdentifier describing it (ex: an ERC-20 token balance on 21 | // a few smart contracts), an account balance request must be made with each AccountIdentifier. The 22 | // `coins` field was removed and replaced by by `/account/coins` in `v1.4.7`. 23 | type AccountBalanceResponse struct { 24 | BlockIdentifier *BlockIdentifier `json:"block_identifier"` 25 | // A single account may have a balance in multiple currencies. 26 | Balances []*Amount `json:"balances"` 27 | // Account-based blockchains that utilize a nonce or sequence number should include that number 28 | // in the metadata. This number could be unique to the identifier or global across the account 29 | // address. 30 | Metadata map[string]interface{} `json:"metadata,omitempty"` 31 | } 32 | -------------------------------------------------------------------------------- /types/account_coin.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | // AccountCoin contains an *AccountIdentifier and a Coin that it owns. 18 | type AccountCoin struct { 19 | Account *AccountIdentifier `json:"account,omitempty"` 20 | Coin *Coin `json:"coin,omitempty"` 21 | } 22 | -------------------------------------------------------------------------------- /types/account_coins_request.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // AccountCoinsRequest AccountCoinsRequest is utilized to make a request on the /account/coins 20 | // endpoint. 21 | type AccountCoinsRequest struct { 22 | NetworkIdentifier *NetworkIdentifier `json:"network_identifier"` 23 | AccountIdentifier *AccountIdentifier `json:"account_identifier"` 24 | // Include state from the mempool when looking up an account's unspent coins. Note, using this 25 | // functionality breaks any guarantee of idempotency. 26 | IncludeMempool bool `json:"include_mempool"` 27 | // In some cases, the caller may not want to retrieve coins for all currencies for an 28 | // AccountIdentifier. If the currencies field is populated, only coins for the specified 29 | // currencies will be returned. If not populated, all unspent coins will be returned. 30 | Currencies []*Currency `json:"currencies,omitempty"` 31 | } 32 | -------------------------------------------------------------------------------- /types/account_coins_response.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // AccountCoinsResponse AccountCoinsResponse is returned on the /account/coins endpoint and includes 20 | // all unspent Coins owned by an AccountIdentifier. 21 | type AccountCoinsResponse struct { 22 | BlockIdentifier *BlockIdentifier `json:"block_identifier"` 23 | // If a blockchain is UTXO-based, all unspent Coins owned by an account_identifier should be 24 | // returned alongside the balance. It is highly recommended to populate this field so that users 25 | // of the Rosetta API implementation don't need to maintain their own indexer to track their 26 | // UTXOs. 27 | Coins []*Coin `json:"coins"` 28 | // Account-based blockchains that utilize a nonce or sequence number should include that number 29 | // in the metadata. This number could be unique to the identifier or global across the account 30 | // address. 31 | Metadata map[string]interface{} `json:"metadata,omitempty"` 32 | } 33 | -------------------------------------------------------------------------------- /types/account_currency.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | // AccountCurrency is a simple struct combining 18 | // a *types.Account and *types.Currency. This can 19 | // be useful for looking up balances. 20 | type AccountCurrency struct { 21 | Account *AccountIdentifier `json:"account_identifier,omitempty"` 22 | Currency *Currency `json:"currency,omitempty"` 23 | } 24 | -------------------------------------------------------------------------------- /types/account_identifier.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // AccountIdentifier The account_identifier uniquely identifies an account within a network. All 20 | // fields in the account_identifier are utilized to determine this uniqueness (including the 21 | // metadata field, if populated). 22 | type AccountIdentifier struct { 23 | // The address may be a cryptographic public key (or some encoding of it) or a provided 24 | // username. 25 | Address string `json:"address"` 26 | SubAccount *SubAccountIdentifier `json:"sub_account,omitempty"` 27 | // Blockchains that utilize a username model (where the address is not a derivative of a 28 | // cryptographic public key) should specify the public key(s) owned by the address in metadata. 29 | Metadata map[string]interface{} `json:"metadata,omitempty"` 30 | } 31 | -------------------------------------------------------------------------------- /types/amount.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // Amount Amount is some Value of a Currency. It is considered invalid to specify a Value without a 20 | // Currency. 21 | type Amount struct { 22 | // Value of the transaction in atomic units represented as an arbitrary-sized signed integer. 23 | // For example, 1 BTC would be represented by a value of 100000000. 24 | Value string `json:"value"` 25 | Currency *Currency `json:"currency"` 26 | Metadata map[string]interface{} `json:"metadata,omitempty"` 27 | } 28 | -------------------------------------------------------------------------------- /types/balance_exemption.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // BalanceExemption BalanceExemption indicates that the balance for an exempt account could change 20 | // without a corresponding Operation. This typically occurs with staking rewards, vesting balances, 21 | // and Currencies with a dynamic supply. Currently, it is possible to exempt an account from strict 22 | // reconciliation by SubAccountIdentifier.Address or by Currency. This means that any account with 23 | // SubAccountIdentifier.Address would be exempt or any balance of a particular Currency would be 24 | // exempt, respectively. BalanceExemptions should be used sparingly as they may introduce 25 | // significant complexity for integrators that attempt to reconcile all account balance changes. If 26 | // your implementation relies on any BalanceExemptions, you MUST implement historical balance lookup 27 | // (the ability to query an account balance at any BlockIdentifier). 28 | type BalanceExemption struct { 29 | // SubAccountAddress is the SubAccountIdentifier.Address that the BalanceExemption applies to 30 | // (regardless of the value of SubAccountIdentifier.Metadata). 31 | SubAccountAddress *string `json:"sub_account_address,omitempty"` 32 | Currency *Currency `json:"currency,omitempty"` 33 | ExemptionType ExemptionType `json:"exemption_type,omitempty"` 34 | } 35 | -------------------------------------------------------------------------------- /types/block.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // Block Blocks contain an array of Transactions that occurred at a particular BlockIdentifier. A 20 | // hard requirement for blocks returned by Rosetta implementations is that they MUST be 21 | // _inalterable_: once a client has requested and received a block identified by a specific 22 | // BlockIndentifier, all future calls for that same BlockIdentifier must return the same block 23 | // contents. 24 | type Block struct { 25 | BlockIdentifier *BlockIdentifier `json:"block_identifier"` 26 | ParentBlockIdentifier *BlockIdentifier `json:"parent_block_identifier"` 27 | // The timestamp of the block in milliseconds since the Unix Epoch. The timestamp is stored in 28 | // milliseconds because some blockchains produce blocks more often than once a second. 29 | Timestamp int64 `json:"timestamp"` 30 | Transactions []*Transaction `json:"transactions"` 31 | Metadata map[string]interface{} `json:"metadata,omitempty"` 32 | } 33 | -------------------------------------------------------------------------------- /types/block_event.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // BlockEvent BlockEvent represents the addition or removal of a BlockIdentifier from storage. 20 | // Streaming BlockEvents allows lightweight clients to update their own state without needing to 21 | // implement their own syncing logic. 22 | type BlockEvent struct { 23 | // sequence is the unique identifier of a BlockEvent within the context of a NetworkIdentifier. 24 | Sequence int64 `json:"sequence"` 25 | BlockIdentifier *BlockIdentifier `json:"block_identifier"` 26 | Type BlockEventType `json:"type"` 27 | } 28 | -------------------------------------------------------------------------------- /types/block_event_type.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // BlockEventType BlockEventType determines if a BlockEvent represents the addition or removal of a 20 | // block. 21 | type BlockEventType string 22 | 23 | // List of BlockEventType 24 | const ( 25 | ADDED BlockEventType = "block_added" 26 | REMOVED BlockEventType = "block_removed" 27 | ) 28 | -------------------------------------------------------------------------------- /types/block_identifier.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // BlockIdentifier The block_identifier uniquely identifies a block in a particular network. 20 | type BlockIdentifier struct { 21 | // This is also known as the block height. 22 | Index int64 `json:"index"` 23 | // This should be normalized according to the case specified in the block_hash_case network 24 | // options. 25 | Hash string `json:"hash"` 26 | } 27 | -------------------------------------------------------------------------------- /types/block_request.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // BlockRequest A BlockRequest is utilized to make a block request on the /block endpoint. 20 | type BlockRequest struct { 21 | NetworkIdentifier *NetworkIdentifier `json:"network_identifier"` 22 | BlockIdentifier *PartialBlockIdentifier `json:"block_identifier"` 23 | } 24 | -------------------------------------------------------------------------------- /types/block_response.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // BlockResponse A BlockResponse includes a fully-populated block or a partially-populated block 20 | // with a list of other transactions to fetch (other_transactions). As a result of the consensus 21 | // algorithm of some blockchains, blocks can be omitted (i.e. certain block indices can be skipped). 22 | // If a query for one of these omitted indices is made, the response should not include a `Block` 23 | // object. It is VERY important to note that blocks MUST still form a canonical, connected chain of 24 | // blocks where each block has a unique index. In other words, the `PartialBlockIdentifier` of a 25 | // block after an omitted block should reference the last non-omitted block. 26 | type BlockResponse struct { 27 | Block *Block `json:"block,omitempty"` 28 | // Some blockchains may require additional transactions to be fetched that weren't returned in 29 | // the block response (ex: block only returns transaction hashes). For blockchains with a lot of 30 | // transactions in each block, this can be very useful as consumers can concurrently fetch all 31 | // transactions returned. 32 | OtherTransactions []*TransactionIdentifier `json:"other_transactions,omitempty"` 33 | } 34 | -------------------------------------------------------------------------------- /types/block_transaction.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // BlockTransaction BlockTransaction contains a populated Transaction and the BlockIdentifier that 20 | // contains it. 21 | type BlockTransaction struct { 22 | BlockIdentifier *BlockIdentifier `json:"block_identifier"` 23 | Transaction *Transaction `json:"transaction"` 24 | } 25 | -------------------------------------------------------------------------------- /types/block_transaction_request.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // BlockTransactionRequest A BlockTransactionRequest is used to fetch a Transaction included in a 20 | // block that is not returned in a BlockResponse. 21 | type BlockTransactionRequest struct { 22 | NetworkIdentifier *NetworkIdentifier `json:"network_identifier"` 23 | BlockIdentifier *BlockIdentifier `json:"block_identifier"` 24 | TransactionIdentifier *TransactionIdentifier `json:"transaction_identifier"` 25 | } 26 | -------------------------------------------------------------------------------- /types/block_transaction_response.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // BlockTransactionResponse A BlockTransactionResponse contains information about a block 20 | // transaction. 21 | type BlockTransactionResponse struct { 22 | Transaction *Transaction `json:"transaction"` 23 | } 24 | -------------------------------------------------------------------------------- /types/call_request.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // CallRequest CallRequest is the input to the `/call` endpoint. 20 | type CallRequest struct { 21 | NetworkIdentifier *NetworkIdentifier `json:"network_identifier"` 22 | // Method is some network-specific procedure call. This method could map to a network-specific 23 | // RPC endpoint, a method in an SDK generated from a smart contract, or some hybrid of the two. 24 | // The implementation must define all available methods in the Allow object. However, it is up 25 | // to the caller to determine which parameters to provide when invoking `/call`. 26 | Method string `json:"method"` 27 | // Parameters is some network-specific argument for a method. It is up to the caller to 28 | // determine which parameters to provide when invoking `/call`. 29 | Parameters map[string]interface{} `json:"parameters"` 30 | } 31 | -------------------------------------------------------------------------------- /types/call_response.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // CallResponse CallResponse contains the result of a `/call` invocation. 20 | type CallResponse struct { 21 | // Result contains the result of the `/call` invocation. This result will not be inspected or 22 | // interpreted by Rosetta tooling and is left to the caller to decode. 23 | Result map[string]interface{} `json:"result"` 24 | // Idempotent indicates that if `/call` is invoked with the same CallRequest again, at any point 25 | // in time, it will return the same CallResponse. Integrators may cache the CallResponse if this 26 | // is set to true to avoid making unnecessary calls to the Rosetta implementation. For this 27 | // reason, implementers should be very conservative about returning true here or they could 28 | // cause issues for the caller. 29 | Idempotent bool `json:"idempotent"` 30 | } 31 | -------------------------------------------------------------------------------- /types/case.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // Case Case specifies the expected case for strings and hashes. 20 | type Case string 21 | 22 | // List of Case 23 | const ( 24 | UpperCase Case = "upper_case" 25 | LowerCase Case = "lower_case" 26 | CaseSensitive Case = "case_sensitive" 27 | Null Case = "null" 28 | ) 29 | -------------------------------------------------------------------------------- /types/coin.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // Coin Coin contains its unique identifier and the amount it represents. 20 | type Coin struct { 21 | CoinIdentifier *CoinIdentifier `json:"coin_identifier"` 22 | Amount *Amount `json:"amount"` 23 | } 24 | -------------------------------------------------------------------------------- /types/coin_action.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // CoinAction CoinActions are different state changes that a Coin can undergo. When a Coin is 20 | // created, it is coin_created. When a Coin is spent, it is coin_spent. It is assumed that a single 21 | // Coin cannot be created or spent more than once. 22 | type CoinAction string 23 | 24 | // List of CoinAction 25 | const ( 26 | CoinCreated CoinAction = "coin_created" 27 | CoinSpent CoinAction = "coin_spent" 28 | ) 29 | -------------------------------------------------------------------------------- /types/coin_change.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // CoinChange CoinChange is used to represent a change in state of a some coin identified by a 20 | // coin_identifier. This object is part of the Operation model and must be populated for UTXO-based 21 | // blockchains. Coincidentally, this abstraction of UTXOs allows for supporting both account-based 22 | // transfers and UTXO-based transfers on the same blockchain (when a transfer is account-based, 23 | // don't populate this model). 24 | type CoinChange struct { 25 | CoinIdentifier *CoinIdentifier `json:"coin_identifier"` 26 | CoinAction CoinAction `json:"coin_action"` 27 | } 28 | -------------------------------------------------------------------------------- /types/coin_identifier.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // CoinIdentifier CoinIdentifier uniquely identifies a Coin. 20 | type CoinIdentifier struct { 21 | // Identifier should be populated with a globally unique identifier of a Coin. In Bitcoin, this 22 | // identifier would be transaction_hash:index. 23 | Identifier string `json:"identifier"` 24 | } 25 | -------------------------------------------------------------------------------- /types/construction_combine_request.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // ConstructionCombineRequest ConstructionCombineRequest is the input to the `/construction/combine` 20 | // endpoint. It contains the unsigned transaction blob returned by `/construction/payloads` and all 21 | // required signatures to create a network transaction. 22 | type ConstructionCombineRequest struct { 23 | NetworkIdentifier *NetworkIdentifier `json:"network_identifier"` 24 | UnsignedTransaction string `json:"unsigned_transaction"` 25 | Signatures []*Signature `json:"signatures"` 26 | } 27 | -------------------------------------------------------------------------------- /types/construction_combine_response.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // ConstructionCombineResponse ConstructionCombineResponse is returned by `/construction/combine`. 20 | // The network payload will be sent directly to the `construction/submit` endpoint. 21 | type ConstructionCombineResponse struct { 22 | SignedTransaction string `json:"signed_transaction"` 23 | } 24 | -------------------------------------------------------------------------------- /types/construction_derive_request.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // ConstructionDeriveRequest ConstructionDeriveRequest is passed to the `/construction/derive` 20 | // endpoint. Network is provided in the request because some blockchains have different address 21 | // formats for different networks. Metadata is provided in the request because some blockchains 22 | // allow for multiple address types (i.e. different address for validators vs normal accounts). 23 | type ConstructionDeriveRequest struct { 24 | NetworkIdentifier *NetworkIdentifier `json:"network_identifier"` 25 | PublicKey *PublicKey `json:"public_key"` 26 | Metadata map[string]interface{} `json:"metadata,omitempty"` 27 | } 28 | -------------------------------------------------------------------------------- /types/construction_hash_request.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // ConstructionHashRequest ConstructionHashRequest is the input to the `/construction/hash` 20 | // endpoint. 21 | type ConstructionHashRequest struct { 22 | NetworkIdentifier *NetworkIdentifier `json:"network_identifier"` 23 | SignedTransaction string `json:"signed_transaction"` 24 | } 25 | -------------------------------------------------------------------------------- /types/construction_metadata_request.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // ConstructionMetadataRequest A ConstructionMetadataRequest is utilized to get information required 20 | // to construct a transaction. The Options object used to specify which metadata to return is left 21 | // purposely unstructured to allow flexibility for implementers. Options is not required in the case 22 | // that there is network-wide metadata of interest. Optionally, the request can also include an 23 | // array of PublicKeys associated with the AccountIdentifiers returned in 24 | // ConstructionPreprocessResponse. 25 | type ConstructionMetadataRequest struct { 26 | NetworkIdentifier *NetworkIdentifier `json:"network_identifier"` 27 | // Some blockchains require different metadata for different types of transaction construction 28 | // (ex: delegation versus a transfer). Instead of requiring a blockchain node to return all 29 | // possible types of metadata for construction (which may require multiple node fetches), the 30 | // client can populate an options object to limit the metadata returned to only the subset 31 | // required. 32 | Options map[string]interface{} `json:"options,omitempty"` 33 | PublicKeys []*PublicKey `json:"public_keys,omitempty"` 34 | } 35 | -------------------------------------------------------------------------------- /types/construction_metadata_response.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // ConstructionMetadataResponse The ConstructionMetadataResponse returns network-specific metadata 20 | // used for transaction construction. Optionally, the implementer can return the suggested fee 21 | // associated with the transaction being constructed. The caller may use this info to adjust the 22 | // intent of the transaction or to create a transaction with a different account that can pay the 23 | // suggested fee. Suggested fee is an array in case fee payment must occur in multiple currencies. 24 | type ConstructionMetadataResponse struct { 25 | Metadata map[string]interface{} `json:"metadata"` 26 | SuggestedFee []*Amount `json:"suggested_fee,omitempty"` 27 | } 28 | -------------------------------------------------------------------------------- /types/construction_parse_request.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // ConstructionParseRequest ConstructionParseRequest is the input to the `/construction/parse` 20 | // endpoint. It allows the caller to parse either an unsigned or signed transaction. 21 | type ConstructionParseRequest struct { 22 | NetworkIdentifier *NetworkIdentifier `json:"network_identifier"` 23 | // Signed is a boolean indicating whether the transaction is signed. 24 | Signed bool `json:"signed"` 25 | // This must be either the unsigned transaction blob returned by `/construction/payloads` or the 26 | // signed transaction blob returned by `/construction/combine`. 27 | Transaction string `json:"transaction"` 28 | } 29 | -------------------------------------------------------------------------------- /types/construction_payloads_request.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // ConstructionPayloadsRequest ConstructionPayloadsRequest is the request to 20 | // `/construction/payloads`. It contains the network, a slice of operations, and arbitrary metadata 21 | // that was returned by the call to `/construction/metadata`. Optionally, the request can also 22 | // include an array of PublicKeys associated with the AccountIdentifiers returned in 23 | // ConstructionPreprocessResponse. 24 | type ConstructionPayloadsRequest struct { 25 | NetworkIdentifier *NetworkIdentifier `json:"network_identifier"` 26 | Operations []*Operation `json:"operations"` 27 | Metadata map[string]interface{} `json:"metadata,omitempty"` 28 | PublicKeys []*PublicKey `json:"public_keys,omitempty"` 29 | } 30 | -------------------------------------------------------------------------------- /types/construction_payloads_response.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // ConstructionPayloadsResponse ConstructionTransactionResponse is returned by 20 | // `/construction/payloads`. It contains an unsigned transaction blob (that is usually needed to 21 | // construct the a network transaction from a collection of signatures) and an array of payloads 22 | // that must be signed by the caller. 23 | type ConstructionPayloadsResponse struct { 24 | UnsignedTransaction string `json:"unsigned_transaction"` 25 | Payloads []*SigningPayload `json:"payloads"` 26 | } 27 | -------------------------------------------------------------------------------- /types/construction_preprocess_response.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // ConstructionPreprocessResponse ConstructionPreprocessResponse contains `options` that will be 20 | // sent unmodified to `/construction/metadata`. If it is not necessary to make a request to 21 | // `/construction/metadata`, `options` should be omitted. Some blockchains require the PublicKey of 22 | // particular AccountIdentifiers to construct a valid transaction. To fetch these PublicKeys, 23 | // populate `required_public_keys` with the AccountIdentifiers associated with the desired 24 | // PublicKeys. If it is not necessary to retrieve any PublicKeys for construction, 25 | // `required_public_keys` should be omitted. 26 | type ConstructionPreprocessResponse struct { 27 | // The options that will be sent directly to `/construction/metadata` by the caller. 28 | Options map[string]interface{} `json:"options,omitempty"` 29 | RequiredPublicKeys []*AccountIdentifier `json:"required_public_keys,omitempty"` 30 | } 31 | -------------------------------------------------------------------------------- /types/construction_submit_request.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // ConstructionSubmitRequest The transaction submission request includes a signed transaction. 20 | type ConstructionSubmitRequest struct { 21 | NetworkIdentifier *NetworkIdentifier `json:"network_identifier"` 22 | SignedTransaction string `json:"signed_transaction"` 23 | } 24 | -------------------------------------------------------------------------------- /types/currency.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // Currency Currency is composed of a canonical Symbol and Decimals. This Decimals value is used to 20 | // convert an Amount.Value from atomic units (Satoshis) to standard units (Bitcoins). 21 | type Currency struct { 22 | // Canonical symbol associated with a currency. 23 | Symbol string `json:"symbol"` 24 | // Number of decimal places in the standard unit representation of the amount. For example, BTC 25 | // has 8 decimals. Note that it is not possible to represent the value of some currency in 26 | // atomic units that is not base 10. 27 | Decimals int32 `json:"decimals"` 28 | // Any additional information related to the currency itself. For example, it would be useful to 29 | // populate this object with the contract address of an ERC-20 token. 30 | Metadata map[string]interface{} `json:"metadata,omitempty"` 31 | } 32 | -------------------------------------------------------------------------------- /types/curve_type.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // CurveType CurveType is the type of cryptographic curve associated with a PublicKey. * secp256k1: 20 | // SEC compressed - `33 bytes` (https://secg.org/sec1-v2.pdf#subsubsection.2.3.3) * secp256r1: SEC 21 | // compressed - `33 bytes` (https://secg.org/sec1-v2.pdf#subsubsection.2.3.3) * edwards25519: `y 22 | // (255-bits) || x-sign-bit (1-bit)` - `32 bytes` (https://ed25519.cr.yp.to/ed25519-20110926.pdf) * 23 | // tweedle: 1st pk : Fq.t (32 bytes) || 2nd pk : Fq.t (32 bytes) 24 | // (https://github.com/CodaProtocol/coda/blob/develop/rfcs/0038-rosetta-construction-api.md#marshal-keys) 25 | // * pallas: `x (255 bits) || y-parity-bit (1-bit) - 32 bytes` (https://github.com/zcash/pasta) 26 | type CurveType string 27 | 28 | // List of CurveType 29 | const ( 30 | Secp256k1 CurveType = "secp256k1" 31 | Secp256r1 CurveType = "secp256r1" 32 | Edwards25519 CurveType = "edwards25519" 33 | Tweedle CurveType = "tweedle" 34 | Pallas CurveType = "pallas" 35 | ) 36 | -------------------------------------------------------------------------------- /types/direction.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // Direction Used by RelatedTransaction to indicate the direction of the relation (i.e. 20 | // cross-shard/cross-network sends may reference `backward` to an earlier transaction and async 21 | // execution may reference `forward`). Can be used to indicate if a transaction relation is from 22 | // child to parent or the reverse. 23 | type Direction string 24 | 25 | // List of Direction 26 | const ( 27 | Forward Direction = "forward" 28 | Backward Direction = "backward" 29 | ) 30 | -------------------------------------------------------------------------------- /types/events_blocks_request.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // EventsBlocksRequest EventsBlocksRequest is utilized to fetch a sequence of BlockEvents indicating 20 | // which blocks were added and removed from storage to reach the current state. 21 | type EventsBlocksRequest struct { 22 | NetworkIdentifier *NetworkIdentifier `json:"network_identifier"` 23 | // offset is the offset into the event stream to sync events from. If this field is not 24 | // populated, we return the limit events backwards from tip. If this is set to 0, we start from 25 | // the beginning. 26 | Offset *int64 `json:"offset,omitempty"` 27 | // limit is the maximum number of events to fetch in one call. The implementation may return <= 28 | // limit events. 29 | Limit *int64 `json:"limit,omitempty"` 30 | } 31 | -------------------------------------------------------------------------------- /types/events_blocks_response.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // EventsBlocksResponse EventsBlocksResponse contains an ordered collection of BlockEvents and the 20 | // max retrievable sequence. 21 | type EventsBlocksResponse struct { 22 | // max_sequence is the maximum available sequence number to fetch. 23 | MaxSequence int64 `json:"max_sequence"` 24 | // events is an array of BlockEvents indicating the order to add and remove blocks to maintain a 25 | // canonical view of blockchain state. Lightweight clients can use this event stream to update 26 | // state without implementing their own block syncing logic. 27 | Events []*BlockEvent `json:"events"` 28 | } 29 | -------------------------------------------------------------------------------- /types/exemption_type.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // ExemptionType ExemptionType is used to indicate if the live balance for an account subject to a 20 | // BalanceExemption could increase above, decrease below, or equal the computed balance. * 21 | // greater_or_equal: The live balance may increase above or equal the computed balance. This 22 | // typically occurs with staking rewards that accrue on each block. * less_or_equal: The live 23 | // balance may decrease below or equal the computed balance. This typically occurs as balance 24 | // moves from locked to spendable on a vesting account. * dynamic: The live balance may increase 25 | // above, decrease below, or equal the computed balance. This typically occurs with tokens that 26 | // have a dynamic supply. 27 | type ExemptionType string 28 | 29 | // List of ExemptionType 30 | const ( 31 | BalanceGreaterOrEqual ExemptionType = "greater_or_equal" 32 | BalanceLessOrEqual ExemptionType = "less_or_equal" 33 | BalanceDynamic ExemptionType = "dynamic" 34 | ) 35 | -------------------------------------------------------------------------------- /types/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/coinbase/rosetta-sdk-go/types 2 | 3 | go 1.19 4 | 5 | require github.com/mitchellh/mapstructure v1.5.0 6 | -------------------------------------------------------------------------------- /types/go.sum: -------------------------------------------------------------------------------- 1 | github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= 2 | github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= 3 | -------------------------------------------------------------------------------- /types/mempool_response.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // MempoolResponse A MempoolResponse contains all transaction identifiers in the mempool for a 20 | // particular network_identifier. 21 | type MempoolResponse struct { 22 | TransactionIdentifiers []*TransactionIdentifier `json:"transaction_identifiers"` 23 | } 24 | -------------------------------------------------------------------------------- /types/mempool_transaction_request.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // MempoolTransactionRequest A MempoolTransactionRequest is utilized to retrieve a transaction from 20 | // the mempool. 21 | type MempoolTransactionRequest struct { 22 | NetworkIdentifier *NetworkIdentifier `json:"network_identifier"` 23 | TransactionIdentifier *TransactionIdentifier `json:"transaction_identifier"` 24 | } 25 | -------------------------------------------------------------------------------- /types/mempool_transaction_response.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // MempoolTransactionResponse A MempoolTransactionResponse contains an estimate of a mempool 20 | // transaction. It may not be possible to know the full impact of a transaction in the mempool (ex: 21 | // fee paid). 22 | type MempoolTransactionResponse struct { 23 | Transaction *Transaction `json:"transaction"` 24 | Metadata map[string]interface{} `json:"metadata,omitempty"` 25 | } 26 | -------------------------------------------------------------------------------- /types/metadata_request.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // MetadataRequest A MetadataRequest is utilized in any request where the only argument is optional 20 | // metadata. 21 | type MetadataRequest struct { 22 | Metadata map[string]interface{} `json:"metadata,omitempty"` 23 | } 24 | -------------------------------------------------------------------------------- /types/network_identifier.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // NetworkIdentifier The network_identifier specifies which network a particular object is 20 | // associated with. 21 | type NetworkIdentifier struct { 22 | Blockchain string `json:"blockchain"` 23 | // If a blockchain has a specific chain-id or network identifier, it should go in this field. It 24 | // is up to the client to determine which network-specific identifier is mainnet or testnet. 25 | Network string `json:"network"` 26 | SubNetworkIdentifier *SubNetworkIdentifier `json:"sub_network_identifier,omitempty"` 27 | } 28 | -------------------------------------------------------------------------------- /types/network_list_response.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // NetworkListResponse A NetworkListResponse contains all NetworkIdentifiers that the node can serve 20 | // information for. 21 | type NetworkListResponse struct { 22 | NetworkIdentifiers []*NetworkIdentifier `json:"network_identifiers"` 23 | } 24 | -------------------------------------------------------------------------------- /types/network_options_response.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // NetworkOptionsResponse NetworkOptionsResponse contains information about the versioning of the 20 | // node and the allowed operation statuses, operation types, and errors. 21 | type NetworkOptionsResponse struct { 22 | Version *Version `json:"version"` 23 | Allow *Allow `json:"allow"` 24 | } 25 | -------------------------------------------------------------------------------- /types/network_request.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // NetworkRequest A NetworkRequest is utilized to retrieve some data specific exclusively to a 20 | // NetworkIdentifier. 21 | type NetworkRequest struct { 22 | NetworkIdentifier *NetworkIdentifier `json:"network_identifier"` 23 | Metadata map[string]interface{} `json:"metadata,omitempty"` 24 | } 25 | -------------------------------------------------------------------------------- /types/network_status_response.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // NetworkStatusResponse NetworkStatusResponse contains basic information about the node's view of a 20 | // blockchain network. It is assumed that any BlockIdentifier.Index less than or equal to 21 | // CurrentBlockIdentifier.Index can be queried. If a Rosetta implementation prunes historical state, 22 | // it should populate the optional `oldest_block_identifier` field with the oldest block available 23 | // to query. If this is not populated, it is assumed that the `genesis_block_identifier` is the 24 | // oldest queryable block. If a Rosetta implementation performs some pre-sync before it is possible 25 | // to query blocks, sync_status should be populated so that clients can still monitor healthiness. 26 | // Without this field, it may appear that the implementation is stuck syncing and needs to be 27 | // terminated. 28 | type NetworkStatusResponse struct { 29 | CurrentBlockIdentifier *BlockIdentifier `json:"current_block_identifier"` 30 | // The timestamp of the block in milliseconds since the Unix Epoch. The timestamp is stored in 31 | // milliseconds because some blockchains produce blocks more often than once a second. 32 | CurrentBlockTimestamp int64 `json:"current_block_timestamp"` 33 | GenesisBlockIdentifier *BlockIdentifier `json:"genesis_block_identifier"` 34 | OldestBlockIdentifier *BlockIdentifier `json:"oldest_block_identifier,omitempty"` 35 | SyncStatus *SyncStatus `json:"sync_status,omitempty"` 36 | Peers []*Peer `json:"peers"` 37 | } 38 | -------------------------------------------------------------------------------- /types/operation_identifier.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // OperationIdentifier The operation_identifier uniquely identifies an operation within a 20 | // transaction. 21 | type OperationIdentifier struct { 22 | // The operation index is used to ensure each operation has a unique identifier within a 23 | // transaction. This index is only relative to the transaction and NOT GLOBAL. The operations in 24 | // each transaction should start from index 0. To clarify, there may not be any notion of an 25 | // operation index in the blockchain being described. 26 | Index int64 `json:"index"` 27 | // Some blockchains specify an operation index that is essential for client use. For example, 28 | // Bitcoin uses a network_index to identify which UTXO was used in a transaction. network_index 29 | // should not be populated if there is no notion of an operation index in a blockchain 30 | // (typically most account-based blockchains). 31 | NetworkIndex *int64 `json:"network_index,omitempty"` 32 | } 33 | -------------------------------------------------------------------------------- /types/operation_status.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // OperationStatus OperationStatus is utilized to indicate which Operation status are considered 20 | // successful. 21 | type OperationStatus struct { 22 | // The status is the network-specific status of the operation. 23 | Status string `json:"status"` 24 | // An Operation is considered successful if the Operation.Amount should affect the 25 | // Operation.Account. Some blockchains (like Bitcoin) only include successful operations in 26 | // blocks but other blockchains (like Ethereum) include unsuccessful operations that incur a 27 | // fee. To reconcile the computed balance from the stream of Operations, it is critical to 28 | // understand which Operation.Status indicate an Operation is successful and should affect an 29 | // Account. 30 | Successful bool `json:"successful"` 31 | } 32 | -------------------------------------------------------------------------------- /types/operator.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // Operator Operator is used by query-related endpoints to determine how to apply conditions. If 20 | // this field is not populated, the default `and` value will be used. 21 | type Operator string 22 | 23 | // List of Operator 24 | const ( 25 | OR Operator = "or" 26 | AND Operator = "and" 27 | ) 28 | -------------------------------------------------------------------------------- /types/partial_block_identifier.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // PartialBlockIdentifier When fetching data by BlockIdentifier, it may be possible to only specify 20 | // the index or hash. If neither property is specified, it is assumed that the client is making a 21 | // request at the current block. 22 | type PartialBlockIdentifier struct { 23 | Index *int64 `json:"index,omitempty"` 24 | Hash *string `json:"hash,omitempty"` 25 | } 26 | -------------------------------------------------------------------------------- /types/peer.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // Peer A Peer is a representation of a node's peer. 20 | type Peer struct { 21 | PeerID string `json:"peer_id"` 22 | Metadata map[string]interface{} `json:"metadata,omitempty"` 23 | } 24 | -------------------------------------------------------------------------------- /types/public_key.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | import ( 20 | "encoding/hex" 21 | "encoding/json" 22 | ) 23 | 24 | // PublicKey PublicKey contains a public key byte array for a particular CurveType encoded in hex. 25 | // Note that there is no PrivateKey struct as this is NEVER the concern of an implementation. 26 | type PublicKey struct { 27 | Bytes []byte `json:"hex_bytes"` 28 | CurveType CurveType `json:"curve_type"` 29 | } 30 | 31 | // MarshalJSON overrides the default JSON marshaler 32 | // and encodes bytes as hex instead of base64. 33 | func (s *PublicKey) MarshalJSON() ([]byte, error) { 34 | type Alias PublicKey 35 | j, err := json.Marshal(struct { 36 | Bytes string `json:"hex_bytes"` 37 | *Alias 38 | }{ 39 | Bytes: hex.EncodeToString(s.Bytes), 40 | Alias: (*Alias)(s), 41 | }) 42 | if err != nil { 43 | return nil, err 44 | } 45 | return j, nil 46 | } 47 | 48 | // UnmarshalJSON overrides the default JSON unmarshaler 49 | // and decodes bytes from hex instead of base64. 50 | func (s *PublicKey) UnmarshalJSON(b []byte) error { 51 | type Alias PublicKey 52 | r := struct { 53 | Bytes string `json:"hex_bytes"` 54 | *Alias 55 | }{ 56 | Alias: (*Alias)(s), 57 | } 58 | err := json.Unmarshal(b, &r) 59 | if err != nil { 60 | return err 61 | } 62 | 63 | bytes, err := hex.DecodeString(r.Bytes) 64 | if err != nil { 65 | return err 66 | } 67 | 68 | s.Bytes = bytes 69 | return nil 70 | } 71 | -------------------------------------------------------------------------------- /types/related_transaction.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // RelatedTransaction The related_transaction allows implementations to link together multiple 20 | // transactions. An unpopulated network identifier indicates that the related transaction is on the 21 | // same network. 22 | type RelatedTransaction struct { 23 | NetworkIdentifier *NetworkIdentifier `json:"network_identifier,omitempty"` 24 | TransactionIdentifier *TransactionIdentifier `json:"transaction_identifier"` 25 | Direction Direction `json:"direction"` 26 | } 27 | -------------------------------------------------------------------------------- /types/search_transactions_response.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // SearchTransactionsResponse SearchTransactionsResponse contains an ordered collection of 20 | // BlockTransactions that match the query in SearchTransactionsRequest. These BlockTransactions are 21 | // sorted from most recent block to oldest block. 22 | type SearchTransactionsResponse struct { 23 | // transactions is an array of BlockTransactions sorted by most recent BlockIdentifier (meaning 24 | // that transactions in recent blocks appear first). If there are many transactions for a 25 | // particular search, transactions may not contain all matching transactions. It is up to the 26 | // caller to paginate these transactions using the max_block field. 27 | Transactions []*BlockTransaction `json:"transactions"` 28 | // total_count is the number of results for a given search. Callers typically use this value to 29 | // concurrently fetch results by offset or to display a virtual page number associated with 30 | // results. 31 | TotalCount int64 `json:"total_count"` 32 | // next_offset is the next offset to use when paginating through transaction results. If this 33 | // field is not populated, there are no more transactions to query. 34 | NextOffset *int64 `json:"next_offset,omitempty"` 35 | } 36 | -------------------------------------------------------------------------------- /types/signature.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | import ( 20 | "encoding/hex" 21 | "encoding/json" 22 | ) 23 | 24 | // Signature Signature contains the payload that was signed, the public keys of the keypairs used to 25 | // produce the signature, the signature (encoded in hex), and the SignatureType. PublicKey is often 26 | // times not known during construction of the signing payloads but may be needed to combine 27 | // signatures properly. 28 | type Signature struct { 29 | SigningPayload *SigningPayload `json:"signing_payload"` 30 | PublicKey *PublicKey `json:"public_key"` 31 | SignatureType SignatureType `json:"signature_type"` 32 | Bytes []byte `json:"hex_bytes"` 33 | } 34 | 35 | // MarshalJSON overrides the default JSON marshaler 36 | // and encodes bytes as hex instead of base64. 37 | func (s *Signature) MarshalJSON() ([]byte, error) { 38 | type Alias Signature 39 | j, err := json.Marshal(struct { 40 | Bytes string `json:"hex_bytes"` 41 | *Alias 42 | }{ 43 | Bytes: hex.EncodeToString(s.Bytes), 44 | Alias: (*Alias)(s), 45 | }) 46 | if err != nil { 47 | return nil, err 48 | } 49 | return j, nil 50 | } 51 | 52 | // UnmarshalJSON overrides the default JSON unmarshaler 53 | // and decodes bytes from hex instead of base64. 54 | func (s *Signature) UnmarshalJSON(b []byte) error { 55 | type Alias Signature 56 | r := struct { 57 | Bytes string `json:"hex_bytes"` 58 | *Alias 59 | }{ 60 | Alias: (*Alias)(s), 61 | } 62 | err := json.Unmarshal(b, &r) 63 | if err != nil { 64 | return err 65 | } 66 | 67 | bytes, err := hex.DecodeString(r.Bytes) 68 | if err != nil { 69 | return err 70 | } 71 | 72 | s.Bytes = bytes 73 | return nil 74 | } 75 | -------------------------------------------------------------------------------- /types/signature_type.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // SignatureType SignatureType is the type of a cryptographic signature. * ecdsa: `r (32-bytes) || s 20 | // (32-bytes)` - `64 bytes` * ecdsa_recovery: `r (32-bytes) || s (32-bytes) || v (1-byte)` - `65 21 | // bytes` * ed25519: `R (32-byte) || s (32-bytes)` - `64 bytes` * schnorr_1: `r (32-bytes) || s 22 | // (32-bytes)` - `64 bytes` (schnorr signature implemented by Zilliqa where both `r` and `s` are 23 | // scalars encoded as `32-bytes` values, most significant byte first.) * schnorr_poseidon: `r 24 | // (32-bytes) || s (32-bytes)` where s = Hash(1st pk || 2nd pk || r) - `64 bytes` (schnorr 25 | // signature w/ Poseidon hash function implemented by O(1) Labs where both `r` and `s` are scalars 26 | // encoded as `32-bytes` values, least significant byte first. 27 | // https://github.com/CodaProtocol/signer-reference/blob/master/schnorr.ml ) 28 | type SignatureType string 29 | 30 | // List of SignatureType 31 | const ( 32 | Ecdsa SignatureType = "ecdsa" 33 | EcdsaRecovery SignatureType = "ecdsa_recovery" 34 | Ed25519 SignatureType = "ed25519" 35 | Schnorr1 SignatureType = "schnorr_1" 36 | SchnorrPoseidon SignatureType = "schnorr_poseidon" 37 | ) 38 | -------------------------------------------------------------------------------- /types/sub_account_identifier.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // SubAccountIdentifier An account may have state specific to a contract address (ERC-20 token) 20 | // and/or a stake (delegated balance). The sub_account_identifier should specify which state (if 21 | // applicable) an account instantiation refers to. 22 | type SubAccountIdentifier struct { 23 | // The SubAccount address may be a cryptographic value or some other identifier (ex: bonded) 24 | // that uniquely specifies a SubAccount. 25 | Address string `json:"address"` 26 | // If the SubAccount address is not sufficient to uniquely specify a SubAccount, any other 27 | // identifying information can be stored here. It is important to note that two SubAccounts with 28 | // identical addresses but differing metadata will not be considered equal by clients. 29 | Metadata map[string]interface{} `json:"metadata,omitempty"` 30 | } 31 | -------------------------------------------------------------------------------- /types/sub_network_identifier.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // SubNetworkIdentifier In blockchains with sharded state, the SubNetworkIdentifier is required to 20 | // query some object on a specific shard. This identifier is optional for all non-sharded 21 | // blockchains. 22 | type SubNetworkIdentifier struct { 23 | Network string `json:"network"` 24 | Metadata map[string]interface{} `json:"metadata,omitempty"` 25 | } 26 | -------------------------------------------------------------------------------- /types/transaction.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // Transaction Transactions contain an array of Operations that are attributable to the same 20 | // TransactionIdentifier. 21 | type Transaction struct { 22 | TransactionIdentifier *TransactionIdentifier `json:"transaction_identifier"` 23 | Operations []*Operation `json:"operations"` 24 | RelatedTransactions []*RelatedTransaction `json:"related_transactions,omitempty"` 25 | // Transactions that are related to other transactions (like a cross-shard transaction) should 26 | // include the tranaction_identifier of these transactions in the metadata. 27 | Metadata map[string]interface{} `json:"metadata,omitempty"` 28 | } 29 | -------------------------------------------------------------------------------- /types/transaction_identifier.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // TransactionIdentifier The transaction_identifier uniquely identifies a transaction in a 20 | // particular network and block or in the mempool. 21 | type TransactionIdentifier struct { 22 | // Any transactions that are attributable only to a block (ex: a block event) should use the 23 | // hash of the block as the identifier. This should be normalized according to the case 24 | // specified in the transaction_hash_case in network options. 25 | Hash string `json:"hash"` 26 | } 27 | -------------------------------------------------------------------------------- /types/transaction_identifier_response.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // TransactionIdentifierResponse TransactionIdentifierResponse contains the transaction_identifier 20 | // of a transaction that was submitted to either `/construction/hash` or `/construction/submit`. 21 | type TransactionIdentifierResponse struct { 22 | TransactionIdentifier *TransactionIdentifier `json:"transaction_identifier"` 23 | Metadata map[string]interface{} `json:"metadata,omitempty"` 24 | } 25 | -------------------------------------------------------------------------------- /types/types.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | const ( 18 | // RosettaAPIVersion is the version of the Rosetta API 19 | // specification used to generate code for this release 20 | // of the SDK. 21 | RosettaAPIVersion = "1.4.12" 22 | ) 23 | -------------------------------------------------------------------------------- /types/version.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Generated by: OpenAPI Generator (https://openapi-generator.tech) 16 | 17 | package types 18 | 19 | // Version The Version object is utilized to inform the client of the versions of different 20 | // components of the Rosetta implementation. 21 | type Version struct { 22 | // The rosetta_version is the version of the Rosetta interface the implementation adheres to. 23 | // This can be useful for clients looking to reliably parse responses. 24 | RosettaVersion string `json:"rosetta_version"` 25 | // The node_version is the canonical version of the node runtime. This can help clients manage 26 | // deployments. 27 | NodeVersion string `json:"node_version"` 28 | // When a middleware server is used to adhere to the Rosetta interface, it should return its 29 | // version here. This can help clients manage deployments. 30 | MiddlewareVersion *string `json:"middleware_version,omitempty"` 31 | // Any other information that may be useful about versioning of dependent services should be 32 | // returned here. 33 | Metadata map[string]interface{} `json:"metadata,omitempty"` 34 | } 35 | -------------------------------------------------------------------------------- /utils/bst_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package utils 16 | 17 | import ( 18 | "testing" 19 | 20 | "github.com/stretchr/testify/assert" 21 | ) 22 | 23 | func TestBST(t *testing.T) { 24 | bst := &BST{} 25 | 26 | // Test empty BST 27 | assert.Nil(t, bst.Get(1)) 28 | assert.Nil(t, bst.Min()) 29 | assert.True(t, bst.Empty()) 30 | 31 | // Set 1 key and ensure it is the min 32 | bst.Set(1, 10) 33 | assert.False(t, bst.Empty()) 34 | assert.Equal(t, 10, bst.Get(1).Value) 35 | assert.Equal(t, int64(1), bst.Min().Key) 36 | assert.Nil(t, bst.Get(10)) 37 | 38 | // Overwrite existing key 39 | bst.Set(1, 11) 40 | assert.Equal(t, 11, bst.Get(1).Value) 41 | assert.Equal(t, int64(1), bst.Min().Key) 42 | 43 | // Add a key that will be put in "left" 44 | // of root 45 | bst.Set(0, 11) 46 | assert.Equal(t, 11, bst.Get(0).Value) 47 | assert.Equal(t, int64(0), bst.Min().Key) 48 | 49 | // Delete root 50 | bst.Delete(1) 51 | assert.Equal(t, 11, bst.Get(0).Value) 52 | assert.Equal(t, int64(0), bst.Min().Key) 53 | assert.Nil(t, bst.Get(1)) 54 | 55 | // Add keys to the "right" of new root 56 | bst.Set(3, 33) 57 | bst.Set(2, 22) 58 | 59 | // Delete already deleted item 60 | bst.Delete(1) 61 | assert.False(t, bst.Empty()) 62 | 63 | // Delete root again 64 | bst.Delete(0) 65 | bst.Delete(0) 66 | assert.False(t, bst.Empty()) 67 | 68 | // Ensure 2 is the min key after root 69 | // deleted 70 | assert.Equal(t, int64(2), bst.Min().Key) 71 | 72 | // Delete all items 73 | bst.Delete(3) 74 | bst.Delete(2) 75 | assert.True(t, bst.Empty()) 76 | assert.Nil(t, bst.Min()) 77 | } 78 | -------------------------------------------------------------------------------- /utils/sharded_map_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Coinbase, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package utils 16 | 17 | import ( 18 | "context" 19 | "testing" 20 | "time" 21 | 22 | "github.com/stretchr/testify/assert" 23 | "golang.org/x/sync/errgroup" 24 | ) 25 | 26 | func TestShardedMap(t *testing.T) { 27 | m := NewShardedMap(2) 28 | g, _ := errgroup.WithContext(context.Background()) 29 | 30 | // To test locking, we use channels 31 | // that will cause deadlock if not executed 32 | // concurrently. 33 | a := make(chan struct{}) 34 | b := make(chan struct{}) 35 | 36 | g.Go(func() error { 37 | s := m.Lock("a", false) 38 | assert.Len(t, s, 0) 39 | s["test"] = "a" 40 | <-a 41 | close(b) 42 | m.Unlock("a") 43 | return nil 44 | }) 45 | 46 | g.Go(func() error { 47 | s := m.Lock("b", false) 48 | assert.Len(t, s, 0) 49 | s["test"] = "b" 50 | close(a) 51 | <-b 52 | m.Unlock("b") 53 | return nil 54 | }) 55 | 56 | time.Sleep(1 * time.Second) 57 | assert.NoError(t, g.Wait()) 58 | 59 | // Ensure keys set correctly 60 | s := m.Lock("a", false) 61 | assert.Len(t, s, 1) 62 | assert.Equal(t, s["test"], "a") 63 | m.Unlock("a") 64 | 65 | s = m.Lock("b", false) 66 | assert.Len(t, s, 1) 67 | assert.Equal(t, s["test"], "b") 68 | m.Unlock("b") 69 | } 70 | --------------------------------------------------------------------------------