go

module
v0.0.0-...-80a1494 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2020 License: OSL-3.0

README

Getting Started with Golang Implementation

Project Structure

├── README.md
├── abi              - Go's code generated from `abigen`
├── cmd/gvel         - `gvel` cli stays here
├── libs/vclient     - Go's client, used by anyone who want to integrate with VELO
├── contract_helper  - the script here helps QA team do automation easier, consult with them for usage
├── Makefile         - a bunch of shortcuts (see detail in later section)
├── go.mod
└── go.sum

Prerequisite

  • Golang 1.12 or higher

Go VCLient

VClient is built for anyone who want to integrate with VELO. It contains a bunch of express functionality such credit setup, credit mint, credit redeem, etc.

Basic Usage
import (
	"github.com/velo-protocol/DRSv2/go/libs/vclient"
)
func main() {
	client, _ := vclient.NewClient("<SMART_CONTRACT_NODE_URL>", "<PRIVATE_KEY>", ContractAddress{
		DrsAddress:   "<DRS_CONTRACT_ADDRESS>",   // 0x4Db9c67836A3735f63c0eCe4cFBc486bB80732b0
		HeartAddress: "<HEART_CONTRACT_ADDRESS>", // 0x1F1247eDEa84dC392C857A7887203a5640f3f2Fd
	})
    
	output, _ := client.SetupCredit(context.Background(), &vclient.SetupCreditInput{
		CollateralAssetCode: "VELO",
		PeggedCurrency:      "USD",
		AssetCode:           "vUSD",
		PeggedValue:         "1.0",
	})
}

See more example usage in example.go from its directory.

Development Tips
Generating mock

Use the make command to generate mock files for vclient

$ make mockgen/all
Generating Go's abi

Use the make command to generate go's abi files

$ make abigen/gen/all

The file's will be stored in ./abi

Go CLI gvel

Building gvel
$ cd cmd/gvel
$ make gvel/build

or just

$ cd go/cmd/gvel
$ go build . 
Development Tips
Software structure

The gvel itself follows Clean Architecture. The layers is divided into

  • commands - this is the outermost layer, in other word, this layer is user interface
  • logic - this layer control the flow of each command input
  • repositories - this layer contains two sublayers
    • database - database repo controls how to interact with database, currently we use leveldb
    • vfactory - vfactory repo controls how the vclient will be initiated
Generating mock

Use the make command to generate mock files for gvel

$ cd cmd/gvel
$ make mockgen/all

Directories

Path Synopsis
cmd
gvel/layers/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
gvel/utils/mocks
Package mockutils is a generated GoMock package.
Package mockutils is a generated GoMock package.
libs
vclient
Package vclient provides client access to a Velo smart contract.
Package vclient provides client access to a Velo smart contract.
vclient/ivclient/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
vclient/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL