• This repository has been archived on 16/Mar/2022
  • Stars
    star
    368
  • Rank 115,958 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 2 years ago

Reviews

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

Repository Details

Clean and lightweight cross-chain transaction API

Block Atlas by Trust Wallet

THIS REPO IS NO LONGER MAINTAINED


Go Version codecov Go Report Card

BlockAtlas is a clean explorer API and transaction observer for cryptocurrencies.

BlockAtlas connects to nodes or explorer APIs of the supported coins and maps transaction data, account transaction history into a generic, easy to work with JSON format.

The observer API watches the chain for new transactions and generates notifications by guids.

Supported Coins

Block Atlas supports more than 25 blockchains: Bitcoin, Ethereum, Binance Chain etc, The full feature matrix is here.

Architecture

Blockatlas allows to:

  • Get information about transactions, tokens, staking details, collectibles for supported coins.
  • Subscribe for price notifications via Rabbit MQ

Platform API is independent service and can work with the specific blockchain only (like Bitcoin, Ethereum, etc)

Notifications:

  • Subscriber Producer - Create new blockatlas.SubscriptionEvent [Not implemented at Atlas, write it on your own]

  • Subscriber - Get subscriptions from queue, set them to the DB

  • Parser - Parse the block, convert block to the transactions batch, send to queue

  • Notifier - Check each transaction for having the same address as stored at DB, if so - send tx data and id to the next queue

  • Notifier Consumer - Notify the user [Not implemented at Atlas, write it on your own]

New Subscriptions --(Rabbit MQ)--> Subscriber --> DB
                                                   |
                      Parser  --(Rabbit MQ)--> Notifier --(Rabbit MQ)--> Notifier Consumer --> User

The whole flow is not available at Atlas repo. We will have integration tests with it. Also there will be examples of all instances soon.

Setup

Prerequisite

  • Go Toolchain versions 1.14+

    Depends on what type of Blockatlas service you would like to run will also be needed.

  • Postgres to store user subscriptions and latest parsed block number

  • Rabbit MQ to pass subscriptions and send transaction notifications

Quick Start

Get source code

Download source to GOPATH

go get -u github.com/trustwallet/blockatlas
cd $(go env GOPATH)/src/github.com/trustwallet/blockatlas

Build and run

Read configuration info

# Start Platform API server at port 8420 with the path to the config.yml ./
go build -o api-bin cmd/api/main.go && ./api-bin -p 8420

# Start parser with the path to the config.yml ./ 
go build -o parser-bin cmd/parser/main.go && ./parser-bin

# Start notifier with the path to the config.yml ./ 
go build -o notifier-bin cmd/notifier/main.go && ./notifier-bin

# Start subscriber with the path to the config.yml ./ 
go build -o subscriber-bin cmd/subscriber/main.go && ./subscriber-bin

make command

Build and start all services:

make go-build
make start

Build and start individual service:

make go-build-api
make start

Docker

Build and run all services:

docker-compose build
docker-compose up

Build and run individual service:

docker-compose build api
docker-compose start api

Configuration

When any of Block Atlas services started they look up inside default configuration. Most coins offering public RPC/explorer APIs are enabled, thus Block Atlas can be started and used right away, no additional configuration needed. By default starting any of the services will enable all platforms

To run a specific service only by passing environmental variable, e.g: ATLAS_PLATFORM=ethereum :

ATLAS_PLATFORM=ethereum go run cmd/api/main.go

ATLAS_PLATFORM=ethereum binance bitcoin go run cmd/api/main.go # for multiple platforms

or change in config file

# Single
platform: [ethereum]
# Multiple 
platform: [ethereum, binance, bitcoin]

This way you can one platform per binary, for scalability and sustainability.

To enable use of private endpoint:

nimiq:
  api: http://localhost:8648

It works the same for worker - you can run all observer at 1 binary or 30 coins per 30 binaries

Environment

The rest gets loaded from environment variables. Every config option is available under the ATLAS_ prefix. Nested keys are joined via _.

Example:

ATLAS_NIMIQ_API=http://localhost:8648

Tests

Unit tests

make test

Mocked tests

End-to-end tests with calls to external APIs has great value, but they are not suitable for regular CI verification, beacuse any external reason could break the tests.

# Start API server with mocked config, at port 8437 ./ 
go build -o api-bin cmd/api/main.go && ./api-bin -p 8437 -c configmock.yml

Therefore mocked API-level tests are used, whereby external APIs are replaced by mocks.

  • External mocks are implemented as a simple, own, golang mockserver. It listens locally, and returns responses to specific API paths, taken from json data files.
  • There is a file where API paths and corresponding data files are listed.
  • Tests invoke into blockatlas through public APIs only, and are executed using newman (Postman cli -- make newman-mocked).
  • Product code, and even test code should not be aware whether it runs with mocks or the real external endpoints.
  • See Makefile for targets with 'mock'; platform can be started locally with mocks using make start-platform-api-mock.
  • The newman tests can be executed with unmocked external APIs as well, but verifications may fail, because some APIs return variable responses. Unmocked tests are not intended for regular CI execution, but as ad-hoc development tests.
  • General steps for creating new mocked tests: replace endpoint to localhost:3347, observe incoming calls (visible in mockserver's output), obtain real response from external API (with exact same parameters), place response in a file, add path + file to data file list. Restart mock, and verify that blockatlas provides correct output. Also, add verifications of results to the tests.

Docs

Swagger API docs provided at path /swagger/index.html

or you can install go-swagger and render it locally (macOS example)

Install:

brew tap go-swagger/go-swagger
brew install go-swagger

Render:

swagger serve docs/swagger.yaml

Updating Docs

More Repositories

1

assets

A comprehensive, up-to-date collection of information about several thousands (!) of crypto tokens.
Go
4,539
star
2

wallet-core

Cross-platform, cross-blockchain wallet library.
C++
2,767
star
3

trust-wallet-ios

πŸ“± Trust - Ethereum Wallet and Web3 DApp Browser for iOS
Swift
1,520
star
4

trust-web3-provider

Web3 javascript wrapper provider for iOS and Android platforms.
TypeScript
747
star
5

trust-wallet-android-source

Trust - Ethereum Wallet for Android (Inactive Repository)
Java
385
star
6

tokens

Upload yours token, coin and dApp image to get displayed in the Trust Wallet
JavaScript
345
star
7

developer

Trust Developer documentation: developer.trustwallet.com
337
star
8

TrustSDK-iOS

No longer maintained. https://community.trustwallet.com/t/trustsdk-is-discontinued/213116
Swift
226
star
9

trust-ray

☁️ API for the Trust Wallet. Project no longer supported and current version used as source of transactions and address tokens in Blockatlas https://github.com/trustwallet/blockatlas/blob/master/config.yml#L64
TypeScript
185
star
10

TrustSDK-Android

No longer maintained. https://community.trustwallet.com/t/trustsdk-is-discontinued/213116
Kotlin
152
star
11

dapps-browser

DApps browser
JavaScript
131
star
12

trust-keystore

A general-purpose Ethereum keystore for managing wallets.
Swift
119
star
13

wallet-connect-swift

WalletConnect Swift client SDK
Swift
102
star
14

go-libs

Go
91
star
15

wallet-connect-kotlin

Kotlin
90
star
16

watchmarket

Watchmarket is an aggregation and caching service for blockchain market information
Go
86
star
17

trustsdk-react-native

No longer maintained. https://community.trustwallet.com/t/trustsdk-is-discontinued/213116
TypeScript
82
star
18

trust-core

DEPRECATED. Please use wallet-core
Swift
70
star
19

go-primitives

Go
59
star
20

Web3View

Java
52
star
21

trust-api

TypeScript
30
star
22

barz

A Secure, Modular, Upgradeable Smart Contract Wallet enabling mass adoption of Web3
TypeScript
28
star
23

ens-coincodec

Go
25
star
24

wizard-sdk

Wizard-SDK, a TypeScript software development kit, is designed to visualize diverse protocol EIP-712 messages and simulate transactions that users sign daily in the web3.0 environment.
TypeScript
25
star
25

ansible-collection-blockchain

Trust Wallet's Ansible Galaxy Collection of roles to configure blockchain nodes.
Jinja
23
star
26

web-core

TypeScript
16
star
27

dokka

WalletCore Kotlin API documentation
Shell
13
star
28

assets-go-libs

Go
12
star
29

web3-react-trust-wallet

TypeScript
10
star
30

trezor-crypto-ios

πŸ“™ Heavily optimized cryptography algorithms for embedded devices, packaged for iOS.
Ruby
9
star
31

docc

WalletCore Swift API documentation
Shell
2
star
32

multiversx

MultiversX metadata
2
star
33

solana-wallet-standard

2
star