• Stars
    star
    182
  • Rank 203,385 (Top 5 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created about 4 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rosetta Client Go SDK

Rosetta

Rosetta SDK

Go SDK to create and interact with Rosetta API implementations

Build once. Integrate your blockchain everywhere.

Overview

The rosetta-sdk-go provides a collection of packages used for interaction with the Rosetta API specification. Much of the code in this repository is generated from the rosetta-specifications repository.

Jump to:

If you have a blockchain based on go-ethereum, we recommend that you use our rosetta-geth-sdk SDK.

Getting Started

This Golang project provides a server package that empowers a developer to write a full Rosetta Data API server by only implementing an interface. This package automatically validates client requests and calls the functions you implement with pre-parsed requests (instead of in raw JSON).

If you plan to use a language other than Golang, you will need to either codegen a server (using Swagger Codegen or OpenAPI Generator) or write one from scratch. If you choose to write an implementation in another language, we ask that you create a separate repository in an SDK-like format for all the code you generate so that other developers can use it. You can add your repository to the list in the rosetta-ecosystem repository, and in the ecosystem category of our community site. Use this repository (rosetta-sdk-go) for an example of how to generate code from this specification.

Installation Guide

This command installs the Server package.

go get github.com/coinbase/rosetta-sdk-go/server

Components

Router

The router is a Mux router that routes traffic to the correct controller.

Controller

Controllers are automatically generated code that specify an interface that a service must implement.

Services

Services are implemented by you to populate responses. These services are invoked by controllers.

Recommended Folder Structure

main.go
/services
  block_service.go
  network_service.go
  ...

Quick Examples

Complete SDK Example

This is an example of how to write an implementation using the Server package in rosetta-sdk-go.

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/coinbase/rosetta-sdk-go/asserter"
	"github.com/coinbase/rosetta-sdk-go/examples/server/services"
	"github.com/coinbase/rosetta-sdk-go/server"
	"github.com/coinbase/rosetta-sdk-go/types"
)

const (
	serverPort = 8080
)

// NewBlockchainRouter creates a Mux http.Handler from a collection
// of server controllers.
func NewBlockchainRouter(
	network *types.NetworkIdentifier,
	asserter *asserter.Asserter,
) http.Handler {
	networkAPIService := services.NewNetworkAPIService(network)
	networkAPIController := server.NewNetworkAPIController(
		networkAPIService,
		asserter,
	)

	blockAPIService := services.NewBlockAPIService(network)
	blockAPIController := server.NewBlockAPIController(
		blockAPIService,
		asserter,
	)

	return server.NewRouter(networkAPIController, blockAPIController)
}

func main() {
	network := &types.NetworkIdentifier{
		Blockchain: "Rosetta",
		Network:    "Testnet",
	}

	// The asserter automatically rejects incorrectly formatted
	// requests.
	asserter, err := asserter.NewServer(
		[]string{"Transfer", "Reward"},
		false,
		[]*types.NetworkIdentifier{network},
		nil,
		false,
		"",
	)
	if err != nil {
		log.Fatal(err)
	}

	// Create the main router handler then apply the logger and Cors
	// middlewares in sequence.
	router := NewBlockchainRouter(network, asserter)
	loggedRouter := server.LoggerMiddleware(router)
	corsRouter := server.CorsMiddleware(loggedRouter)
	log.Printf("Listening on port %d\n", serverPort)
	log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", serverPort), corsRouter))
}

SDK Packages

  • Types: Auto-generated Rosetta types
  • Client: Low-level communication with any Rosetta server
  • Server: Simplified Rosetta API server development
  • Asserter: Validation of Rosetta types
  • Fetcher: Simplified and validated communication with any Rosetta server
  • Parser: Tool for parsing Rosetta blocks
  • Syncer: Sync Rosetta blocks with customizable handling
  • Reconciler: Compare derived balances with node balances
  • Keys: Cryptographic operations for Rosetta-supported curves
  • Constructor: Coordinate the construction and broadcast of transactions

These packages are demoed extensively in examples and are utilized throughout the rosetta-cli tool.

Syncer

The core of any integration is syncing blocks reliably. The syncer serially processes blocks from a Data API implementation (automatically handling re-orgs) with user-defined handling logic and pluggable storage. After a block is processed, store it to a DB or send a push notificationβ€”the decision is up to you!

Parser

When reading the operations in a block, it's helpful to apply higher-level groupings to related operations, or match operations in a transaction to some set of generic descriptions (i.e., ensure there are two operations of equal but opposite amounts). The parser empowers any integrator to build abstractions on top of the building blocks that the Rosetta API exposes.

Development

Helpful commands for development:

Install Dependencies

make deps

Generate Types, Client and Server

make gen

If you want to modify client and server, please modify files under templates/client and templates/server then run make gen

Run Tests

make test

Lint the Source Code

This includes the generated code.

make lint

Code Check

make release

Testing

To validate rosetta-sdk-go, install rosetta-cli and run one of the following commands:

  • rosetta-cli check:data --configuration-file rosetta-cli-conf/testnet/config.json - This command validates that the Data API implementation is correct, using the bitcoin testnet node. It also ensures that the implementation does not miss any balance-changing operations.
  • rosetta-cli check:construction --configuration-file rosetta-cli-conf/testnet/config.json - This command validates the Construction API implementation. It also verifies transaction construction, signing, and submissions to the testnet network.
  • rosetta-cli check:data --configuration-file rosetta-cli-conf/mainnet/config.json - This command validates that the Data API implementation is correct, using the bitcoin mainnet node. It also ensures that the implementation does not miss any balance-changing operations.

Read the How to Test your Rosetta Implementation documentation for additional details.

Contributing

You may contribute to the rosetta-sdk-go project in various ways:

Read our Contributing documentation for more information.

When you've finished an implementation for a blockchain, share your work in the ecosystem category of the community site. Platforms looking for implementations for certain blockchains will be monitoring this section of the website for high-quality implementations they can use for integration. Make sure that your implementation meets the expectations of any implementation.

Documentation

You can find the Rosetta API documentation at rosetta-api.org.

Check out the Getting Started section to start diving into Rosetta.

Our documentation is divided into the following sections:

Related Projects

  • rosetta-specifications β€” The rosetta-specifications repository generates the SDK code in the rosetta-sdk-go repository.
  • rosetta-cli β€” Use the rosetta-cli tool to test your Rosetta API implementation. The tool also provides the ability to look up block contents and account balances.
  • rosetta-geth-sdk – The rosetta-geth-sdk repository provides a collection of packages used for interaction with the Rosetta API specification. The goal of this SDK is to help accelerate Rosetta API implementation on go-ethereum based chains.

Sample Implementations

To help you with examples, we developed complete Rosetta API sample implementations for Bitcoin and Ethereum. Developers of Bitcoin-like or Ethereum-like blockchains may find it easier to fork these implementation samples than to write an implementation from scratch.

You can also find community implementations for a variety of blockchains in the rosetta-ecosystem repository, and in the ecosystem category of our community site.

License

This project is available open source under the terms of the Apache 2.0 License.

Β© 2022 Coinbase

More Repositories

1

terraform-landscape

Improve Terraform's plan output to be easier to read and understand
Ruby
1,546
star
2

coinbase-wallet-sdk

An open protocol that lets users connect their mobile wallets to your DApp
TypeScript
1,276
star
3

coinbase-pro-trading-toolkit

DEPRECATED β€” The Coinbase Pro trading toolkit
TypeScript
856
star
4

kryptology

Go
838
star
5

coinbase-pro-node

DEPRECATED β€” The official Node.js library for Coinbase Pro
JavaScript
828
star
6

build-onchain-apps

Accelerate your web3 creativity with the Build Onchain Apps Toolkit. ⛡️
TypeScript
570
star
7

odin

Archived: Odin deployer to AWS for 12 Factor applications.
Go
540
star
8

coinbase-python

DEPRECATED β€” Coinbase Python API
Python
511
star
9

assume-role

DEPRECATED β€” assume-role: a CLI tool making it easy to assume IAM roles through an AWS Bastion account
Shell
424
star
10

geoengineer

DEPRECATED β€” Infrastructure As Code
Ruby
403
star
11

coinbase-node

DEPRECATED β€” The official Node.js library for the Coinbase API.
JavaScript
361
star
12

mesh-specifications

Specification files for the Rosetta Blockchain Standard
Shell
313
star
13

coinbase-php

DEPRECATED β€” PHP wrapper for the Coinbase API
PHP
293
star
14

onchainkit

React components and TypeScript utilities for top-tier onchain apps.
TypeScript
287
star
15

cbpay-js

Coinbase Pay SDK
TypeScript
270
star
16

coinbase-ruby

DEPRECATED β€” Ruby wrapper for the Coinbase API
Ruby
239
star
17

waas-sdk-react-native

Coinbase Wallet as a Service (WaaS) SDK for React Native. Enables MPC Operations for iOS and Android Devices.
TypeScript
222
star
18

step

step is a framework for building, testing and deploying AWS Step Functions and Lambda
Go
207
star
19

wallet-mobile-sdk

An open protocol for mobile web3 apps to interact with wallets
Kotlin
203
star
20

temporal-ruby

Ruby SDK for Temporal
Ruby
194
star
21

coinbase-ios-sdk

Integrate bitcoin into your iOS application with Coinbase
Swift
172
star
22

nft-dapp-starter-kit

Starter kit for developers who want to build an NFT minting site
TypeScript
153
star
23

coinbase-java

Coinbase API v1 library for Java
Java
146
star
24

coinbase-commerce-node

Coinbase Commerce Node
JavaScript
143
star
25

mesh-cli

CLI for the Rosetta API
Go
142
star
26

waas-client-library-go

Coinbase Wallet as a Service (WaaS) Client Library in Go.
Go
138
star
27

traffic_jam

DEPRECATED β€” Ruby library for time-based rate limiting
Ruby
129
star
28

coinbase-commerce-php

Coinbase Commerce PHP
PHP
127
star
29

coinbase-exchange-ruby

DEPRECATED β€” Official Ruby library for the GDAX API
Ruby
122
star
30

dexter

Forensics acquisition framework designed to be extensible and secure
Go
118
star
31

multisig-tool

DEPRECATED β€” Multisig Vault recovery tool
JavaScript
110
star
32

mesh-bitcoin

Bitcoin Rosetta API Implementation
Go
104
star
33

smart-wallet

Solidity
103
star
34

mesh-ethereum

Ethereum Rosetta API Implementation
Go
98
star
35

coinbase-android-sdk

DEPRECATED β€” Android SDK for Coinbase
Java
95
star
36

mongobetween

Go
93
star
37

fenrir

Archived: AWS SAM deployer to manage serverless projects.
Go
91
star
38

react-coinbase-commerce

Coinbase Commerce React
JavaScript
91
star
39

pwnbot

You call PwnBot in Slack on someone else's unlocked computer
JavaScript
89
star
40

digital-asset-policy-proposal

Digital Asset Policy Proposal: Safeguarding America’s Financial Leadership
85
star
41

coinbase-commerce-python

Coinbase Commerce Python
Python
77
star
42

CBTabViewExample

TypeScript
69
star
43

coinbase-bitmonet-sdk

DEPRECATED β€” Library to accept bitcoin payments in your Android App
Java
62
star
44

chainstorage

The File System For a Multi-Blockchain World
Go
61
star
45

self-service-iam

DEPRECATED β€” Self Service AWS IAM Policies for dev at scale
JavaScript
58
star
46

coinbase-wordpress

DEPRECATED β€” Coinbase plugin/widget for Wordpress
57
star
47

coinbase-commerce-woocommerce

Accept Bitcoin on your WooCommerce-powered website.
PHP
55
star
48

barbar

DEPRECATED β€” OSX crypto-currency price ticker
Swift
53
star
49

demeter

DEPRECATED β€” Security Group Management For AWS
Ruby
52
star
50

verifications

πŸ“œ "Coinbase Verifications" is a set of Coinbase-verified onchain attestations that enable access to apps and other onchain benefits.
Solidity
50
star
51

coinbase-exchange-node

DEPRECATED β€” Use gdax-node
JavaScript
46
star
52

cadence-ruby

Ruby SDK for Cadence
Ruby
44
star
53

commerce-onchain-payment-protocol

Solidity
41
star
54

protoc-gen-rbi

Protobuf compiler plugin that generates Sorbet .rbi "Ruby Interface" files.
Go
38
star
55

coinbase-woocommerce

DEPRECATED β€” Accept Bitcoin on your WooCommerce-powered website.
38
star
56

coinbase-advanced-py

The Advanced API Python SDK is a Python package that makes it easy to interact with the Coinbase Advanced API. The SDK handles authentication, HTTP connections, and provides helpful methods for interacting with the API.
Python
37
star
57

mesh-ecosystem

Repository of all open source Rosetta implementations and SDKs
33
star
58

master_lock

Inter-process locking library using Redis.
Ruby
31
star
59

coinbase-commerce-ruby

Coinbase Commerce Ruby Gem
Ruby
30
star
60

watchdog

DEPRECATED -- Github Bot for Datadog codification
Go
28
star
61

bittip

DEPRECATED β€” Reddit tip bot
JavaScript
27
star
62

maxfuzz

DEPRECATED β€” Containerized Cloud Fuzzing
C
26
star
63

cash-addr

Utility to convert between base58 and CashAddr BCH addresses.
Ruby
25
star
64

rules_ruby

Bazel Ruby Rules
Starlark
24
star
65

mesh-geth-sdk

go-ethereum based sdk for Rosetta API
Go
23
star
66

gtt-ui

DEPRECATED
JavaScript
22
star
67

btcexport

Export process for Bitcoin blockchain data to CSV
Go
22
star
68

bchd-explorer

Vue
21
star
69

redisbetween

Go
20
star
70

baseca

Go
18
star
71

coinbase-magento

DEPRECATED β€” Accept Bitcoin on your Magento-powered website.
17
star
72

coinbase-commerce-whmcs

Coinbase Commerce module for WHMCS
PHP
16
star
73

coinbase-android-sdk-example

DEPRECATED β€” Example android app leveraging the coinbase android sdk
Java
15
star
74

coinbase-nft-floor-price

Coinbase NFT floor price estimate model
Python
15
star
75

coinbase-spree

DEPRECATED β€” Accept bitcoin payments on your Spree store with Coinbase.
15
star
76

service_variables

Service level variables backed by Redis - useful for service wide configuration.
Ruby
12
star
77

solidity-workshop

JavaScript
12
star
78

omniauth-coinbase

DEPRECATED β€” Coinbase OAuth 2 Strategy for Omniauth
Ruby
12
star
79

coinbase-javascript-sdk

DEPRECATED
JavaScript
11
star
80

coinbase-commerce-prestashop

DEPRECATED β€” Official Coinbase Commerce Prestashop Payment Module
PHP
11
star
81

wrapped-tokens-os

TypeScript
11
star
82

coinbase-cloud-sdk-js

TypeScript
11
star
83

step-asg-deployer

Deprecated, renamed and maintained at https://github.com/coinbase/odin
Go
10
star
84

eip-token-upgrade

Solidity
10
star
85

mkr-vote-proxy

Cold storage-friendly voting for MKR tokens
Solidity
10
star
86

salus

We would like to request that all contributors please clone a *fresh copy* of this repository since the September 21st maintenance.
HTML
9
star
87

chainsformer

Go
9
star
88

coinbase-magento2

DEPRECATED: Accept Bitcoin on your Magento2-powered website.
8
star
89

code-of-conduct

Code of conduct for open source projects managed by Coinbase
8
star
90

coinbase-commerce-opencart

DEPRECATED β€” Coinbase Commerce Integration For Opencart
PHP
8
star
91

magic-spend

Solidity
8
star
92

chainnode

Go
7
star
93

waas-proxy-server

Go
7
star
94

client-analytics

TypeScript
7
star
95

node-process-lock

DEPRECATED β€” Simple process locking using Redis.
JavaScript
7
star
96

coinbase-commerce-magento

DEPRECATED β€” Coinbase Commerce Payment Gateway For Magento 2
PHP
7
star
97

coinbase-commerce-gravity-forms

DEPRECATED β€” Official Coinbase Commerce Payment Gateway For Gravity Forms
PHP
7
star
98

paymaster-bundler-examples

7
star
99

coinbase-zencart

DEPRECATED β€” Accept Bitcoin on your Zen Cart-powered website.
6
star
100

demeter-example

DEPRECATED β€” Demeter
6
star