philippgille / libra-sdk-go

Go SDK for the Libra cryptocurrency

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Related projects

About

Go SDK for the Libra cryptocurrency

License:Mozilla Public License 2.0


Languages

Language:Go 96.4%Language:Shell 3.6%