tron

package module
v0.0.0-...-fd964dd Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2019 License: MIT Imports: 5 Imported by: 2

README

Go-Tron

A Tron API implementation written in Go

Notice

This API is currently in alpha and it is not recommended it be used in production. Use this at your own risk. When the API is stablized this notice will be removed and an issue will be filed indicating that it is safe to use. This will be done when test coverage hits a healthy percentage and the API has matured a bit.

Examples

Transfer
package main

import (
	"github.com/0x10f/go-tron/account"
	"github.com/0x10f/go-tron/client"
	"log"
)

const (
  	srcPrivKey  = "000000000000000000000000000000000000000000000000000000000000010f"
  	destPrivKey = "000000000000000000000000000000000000000000000000000000000000010e"
)
  
func main() {
	src, err := account.FromPrivateKeyHex(srcPrivKey)
	if err != nil {
		log.Fatal("Failed to parse private key hex - ", err)
	}

	dest, err := account.FromPrivateKeyHex(destPrivKey)
	if err != nil { 
		log.Fatal("Failed to parse private key hex - ", err)
	}

	cli := client.New("http://127.0.0.1:16667")

	tx, err := cli.Transfer(src, dest.Address(), 1000000 /* in sun */)
	if err != nil {
		log.Fatal("Failed to transfer tron balance - ", err)
	}

	log.Printf("%#v\n", tx)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressableSigner

type AddressableSigner interface {
	Address() address.Address
	Signer
}

type Block

type Block struct {
	Id           string        `json:"blockId"`
	BlockHeader  BlockHeader   `json:"block_header"`
	Transactions []Transaction `json:"transactions"`
}

type BlockHeader

type BlockHeader struct {
	RawData struct {
		Number              uint64 `json:"number"`
		TransactionTrieRoot string `json:"txTrieRoot"`
		WitnessAddress      string `json:"witness_address"`
		ParentHash          string `json:"parentHash"`
		Version             uint64 `json:"version"`
		Timestamp           uint64 `json:"timestamp"`
	} `json:"raw_data"`
	WitnessSignature string `json:"witness_signature"`
}

type Signable

type Signable interface {
	Sign(key *ecdsa.PrivateKey) error
}

Signable is an interface for implementations of signable objects. Implementations may choose if it accepts one or many signatures.

type Signer

type Signer interface {
	Sign(signable Signable) error
}

Signer is an interface for implementations of objects that append signatures to signable objects.

type Transaction

type Transaction struct {
	Id              string           `json:"txID"`
	Signatures      []string         `json:"signature"`
	Results         *json.RawMessage `json:"ret"`
	ConstantResults *json.RawMessage `json:"constant_result"`
	Visible         *json.RawMessage `json:"visible"`
	RawData         *json.RawMessage `json:"raw_data"`
	RawDataHex      *json.RawMessage `json:"raw_data_hex"`
	ContractAddress *json.RawMessage `json:"contract_address"`
}

func (*Transaction) Sign

func (tx *Transaction) Sign(key *ecdsa.PrivateKey) error

Directories

Path Synopsis
Package account provides functionality for managing Tron network accounts.
Package account provides functionality for managing Tron network accounts.
Package address provides functionality for parsing and manipulating Tron addresses.
Package address provides functionality for parsing and manipulating Tron addresses.
Package client provides functionality for interacting with the Tron node RESTful APIs.
Package client provides functionality for interacting with the Tron node RESTful APIs.
cmd

Jump to

Keyboard shortcuts

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