libra

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2019 License: MPL-2.0 Imports: 10 Imported by: 0

README

libra-sdk-go

GoDoc Build Status Go Report Card

Go SDK for the Libra cryptocurrency

Note: This is work in progress! The API is not stable and will definitely change in the future!
This package uses proper semantic versioning though, so you can use vendoring or Go modules to prevent breaking your build.
The changelog of this package can be viewed here

Features

  • Get account state with account resource (balance, auth key, sent and received events count, sequence no)
  • Send transaction (raw bytes)
Roadmap
  • Instead of the current Transaction struct that only takes RawBytes, a higher level transaction struct will be added with fields for the sender and receiver address as well as amount of Libra Coins to send.
  • A wallet package will be added that can read a recovery file or take a recovery seed string and create accounts with their public/private keypairs from that
  • And much more...

Usage

Example:

package main

import (
    "fmt"
    "time"

    libra "github.com/philippgille/libra-sdk-go"
)

func main() {
    c, err := libra.NewClient("ac.testnet.libra.org:8000", time.Second)
    if err != nil {
        panic(err)
    }
    defer c.Close()

    acc := "8cd377191fe0ef113455c8e8d769f0c0147d5bb618bf195c0af31a05fbfd0969"
    accState, err := c.GetAccountState(acc)
    if err != nil {
        panic(err)
    }

    fmt.Printf("Raw account state: 0x%x\n", accState.Blob)
    fmt.Println()
    fmt.Printf("Account resource: %v\n", accState.AccountResource)
}

Currently prints:

Raw account state: 0x010000002100000001217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc9744000000200000008cd377191fe0ef113455c8e8d769f0c0147d5bb618bf195c0af31a05fbfd0969a0acb90300000000010000000000000004000000000000000400000000000000

Account resource: {"authentication_key": "0x8cd377191fe0ef113455c8e8d769f0c0147d5bb618bf195c0af31a05fbfd0969", "balance": "62500000", "received_events_count": "1", "sent_events_count": "4", "sequence_number": "4"}

Develop

The proto files are taken from the Libra repository, commit 4e27604264bd0a5d6c64427f738cbc84d9258a61.

For updating the rpc package you currently need to manually update the proto files, make some changes (e.g. go_package option) and then run the Go code generation script: scripts/generate_rpc.sh

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountResource added in v0.2.0

type AccountResource struct {
	AuthKey        []byte
	Balance        uint64
	ReceivedEvents uint64
	SentEvents     uint64
	SequenceNo     uint64
}

AccountResource represents an account with its balance etc.

func FromAccountResourceBlob added in v0.2.0

func FromAccountResourceBlob(accountResourceBlob []byte) (AccountResource, error)

FromAccountResourceBlob converts an account resource blob into an object of the AccountState struct.

func (AccountResource) String added in v0.2.0

func (ar AccountResource) String() string

String formats the account state similarly to the Libra CLI. Numbers are formatted as string because the numbers are uint64, whose max value exceeds JSON's "safe integer", which can lead to parsing errors.

Info about JSON's "safe integer": https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER

type AccountState added in v0.2.0

type AccountState struct {
	// The whole account state as raw bytes
	Blob []byte
	// The account resource with balance etc.
	AccountResource AccountResource
}

AccountState represents the state of an account.

func FromAccountStateBlob added in v0.2.0

func FromAccountStateBlob(accountStateBlob []byte) (AccountState, error)

FromAccountStateBlob converts an account state blob into an object of the AccountState struct.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a libra client that's connected to a validator node via gRPC. It allows you to query the account state, send transactions etc.

func NewClient

func NewClient(address string, dialTimeout time.Duration) (Client, error)

NewClient creates a new Libra client. It connects to the given validator node via gRPC. The connection is kept open until Close() is called on the client.

func (Client) Close

func (c Client) Close()

Close closes the underlying gRPC connection.

func (Client) GetAccountState

func (c Client) GetAccountState(accountAddr string) (AccountState, error)

GetAccountState requests the state of the given account.

func (Client) SendTx

func (c Client) SendTx(tx Transaction) error

SendTx sends a transaction to the connected validator node.

type Transaction

type Transaction struct {
	RawBytes     []byte
	SenderPubKey []byte
	SenderSig    []byte
}

Transaction is a transaction of Libra Coins.

Directories

Path Synopsis
rpc

Jump to

Keyboard shortcuts

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