-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from fbsobreira/v2
V2
- Loading branch information
Showing
135 changed files
with
6,541 additions
and
4,610 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.idea | ||
routers/commentsRouter_controllers.go | ||
gotron | ||
*.tmp | ||
vendor/** | ||
tronctl | ||
tonctl-docs | ||
bin | ||
.idea/ | ||
*.key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
path = protocol | ||
url = https://github.com/tronprotocol/protocol.git | ||
branch = master | ||
ignore = dirty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
SHELL := /bin/bash | ||
version := $(shell git rev-list --count HEAD) | ||
commit := $(shell git describe --always --long --dirty) | ||
built_at := $(shell date +%FT%T%z) | ||
built_by := ${USER}@cryptochain.network | ||
BUILD_TARGET := tronctl | ||
|
||
flags := -gcflags="all=-N -l -c 2" | ||
ldflags := -X main.version=v${version} -X main.commit=${commit} | ||
ldflags += -X main.builtAt=${built_at} -X main.builtBy=${built_by} | ||
cli := ./bin/${BUILD_TARGET} | ||
uname := $(shell uname) | ||
|
||
env := GO111MODULE=on | ||
|
||
DIR := ${CURDIR} | ||
export CGO_LDFLAGS=-L$(DIR)/bin/lib -Wl,-rpath -Wl,\$ORIGIN/lib | ||
|
||
all: | ||
$(env) go build -o $(cli) -ldflags="$(ldflags)" cmd/main.go | ||
|
||
debug: | ||
$(env) go build $(flags) -o $(cli) -ldflags="$(ldflags)" cmd/main.go | ||
|
||
install:all | ||
cp $(cli) ~/.local/bin | ||
|
||
clean: | ||
@rm -f $(cli) | ||
@rm -rf ./bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,63 @@ | ||
## gotron ![](https://img.shields.io/badge/progress-80%25-yellow.svg) | ||
# TRON's go-sdk | ||
|
||
GoSDK and TRON-CLI tool for TRON's blockchain via GRPC | ||
|
||
Fork from [sasaxie/go-client-api](https://github.com/sasaxie/go-client-api) | ||
# Build | ||
|
||
|
||
## Requirements | ||
``` | ||
$ git pull -r origin master | ||
$ make | ||
``` | ||
|
||
- Go 1.13 or higher | ||
# Usage & Examples | ||
|
||
## Installation | ||
# bash completions | ||
|
||
First you need to install ProtocolBuffers 3.0.0-beta-3 or later. | ||
once built, add `tronctl` to your path and add to your `.bashrc` | ||
|
||
```sh | ||
mkdir tmp | ||
cd tmp | ||
git clone https://github.com/google/protobuf | ||
cd protobuf | ||
./autogen.sh | ||
./configure | ||
make | ||
make check | ||
sudo make install | ||
``` | ||
. <(tronctl completion) | ||
``` | ||
|
||
Then, `go get -u` as usual the following packages: | ||
|
||
```sh | ||
go get -u github.com/golang/protobuf/protoc-gen-go | ||
## Transfer JSON file format | ||
The JSON file will be a JSON array where each element has the following attributes: | ||
|
||
| Key | Value-type | Value-description| | ||
| :------------------:|:----------:| :----------------| | ||
| `from` | string | [**Required**] Sender's one address, must have key in keystore. | | ||
| `to` | string | [**Required**] The receivers one address. | | ||
| `amount` | string | [**Required**] The amount to send in $ONE. | | ||
| `passphrase-file` | string | [*Optional*] The file path to file containing the passphrase in plain text. If none is provided, check for passphrase string. | | ||
| `passphrase-string` | string | [*Optional*] The passphrase as a string in plain text. If none is provided, passphrase is ''. | | ||
| `stop-on-error` | boolean | [*Optional*] If true, stop sending transactions if an error occurred, default is false. | | ||
|
||
Example of JSON file: | ||
|
||
```json | ||
[ | ||
{ | ||
"from": "TUEZSdKsoDHQMeZwihtdoBiN46zxhGWYdH", | ||
"to": "TKSXDA8HfE9E1y39RczVQ1ZascUEtaSToF", | ||
"amount": "1", | ||
"passphrase-string": "", | ||
"stop-on-error": true | ||
}, | ||
{ | ||
"from": "TUEZSdKsoDHQMeZwihtdoBiN46zxhGWYdH", | ||
"to": "TEvHMZWyfjCAdDJEKYxYVL8rRpigddLC1R", | ||
"amount": "1", | ||
"passphrase-file": "./pw.txt", | ||
} | ||
] | ||
``` | ||
|
||
Update protocol: | ||
|
||
```sh | ||
git submodule update --remote | ||
``` | ||
# Debugging | ||
|
||
Example: | ||
The gotron-sdk code respects `GOTRON_SDK_DEBUG` as debugging | ||
based environment variables. | ||
|
||
```sh | ||
go get -u github.com/fbsobreira/gotron | ||
go run program/getnowblock.go -grpcAddress grpc.trongrid.io:50051 | ||
```bash | ||
GOTRON_SDK_DEBUG=true ./tronctl | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
|
||
cmd "github.com/fbsobreira/gotron-sdk/cmd/subcommands" | ||
// Need this side effect | ||
_ "github.com/fbsobreira/gotron-sdk/pkg/store" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
version string | ||
commit string | ||
builtAt string | ||
builtBy string | ||
) | ||
|
||
func main() { | ||
// HACK Force usage of go implementation rather than the C based one. Do the right way, see the | ||
// notes one line 66,67 of https://golang.org/src/net/net.go that say can make the decision at | ||
// build time. | ||
os.Setenv("GODEBUG", "netdns=go") | ||
cmd.VersionWrapDump = version + "-" + commit | ||
cmd.RootCmd.AddCommand(&cobra.Command{ | ||
Use: "version", | ||
Short: "Show version", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
fmt.Fprintf(os.Stderr, | ||
"TronCTL. %v version %v-%v (%v %v)\n", | ||
path.Base(os.Args[0]), version, commit, builtBy, builtAt) | ||
os.Exit(0) | ||
return nil | ||
}, | ||
}) | ||
cmd.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/fbsobreira/gotron-sdk/pkg/client/transaction" | ||
"github.com/fbsobreira/gotron-sdk/pkg/common" | ||
"github.com/fbsobreira/gotron-sdk/pkg/keystore" | ||
"github.com/fbsobreira/gotron-sdk/pkg/store" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
balanceDetails bool | ||
) | ||
|
||
func accountSub() []*cobra.Command { | ||
cmdBalance := &cobra.Command{ | ||
Use: "balance <ACCOUNT_NAME>", | ||
Short: "Check account balance", | ||
Long: "Query for the latest account balance given Address", | ||
Args: cobra.ExactArgs(1), | ||
PreRunE: validateAddress, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
acc, err := conn.GetAccount(addr.String()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if noPrettyOutput { | ||
fmt.Println(acc) | ||
return nil | ||
} | ||
|
||
result := make(map[string]interface{}) | ||
result["address"] = addr.String() | ||
result["type"] = acc.GetType() | ||
result["name"] = acc.GetAccountName() | ||
result["balance"] = float64(acc.GetBalance()) / 1000000 | ||
asJSON, _ := json.Marshal(result) | ||
fmt.Println(common.JSONPrettyFormat(string(asJSON))) | ||
return nil | ||
}, | ||
} | ||
cmdBalance.Flags().BoolVar(&balanceDetails, "details", false, "") | ||
|
||
cmdActivate := &cobra.Command{ | ||
Use: "activate <ADDRESS_TO_ACTIVATE>", | ||
Short: "activate an address", | ||
Args: cobra.ExactArgs(1), | ||
PreRunE: validateAddress, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if signerAddress.String() == "" { | ||
return fmt.Errorf("no signer specified") | ||
} | ||
tx, err := conn.CreateAccount(signerAddress.String(), addr.String()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var ctrlr *transaction.Controller | ||
if useLedgerWallet { | ||
account := keystore.Account{Address: signerAddress.GetAddress()} | ||
ctrlr = transaction.NewController(conn, nil, &account, tx.Transaction, opts) | ||
} else { | ||
ks, acct, err := store.UnlockedKeystore(signerAddress.String(), passphrase) | ||
if err != nil { | ||
return err | ||
} | ||
ctrlr = transaction.NewController(conn, ks, acct, tx.Transaction, opts) | ||
} | ||
if err = ctrlr.ExecuteTransaction(0); err != nil { | ||
return err | ||
} | ||
|
||
if noPrettyOutput { | ||
fmt.Println(tx) | ||
return nil | ||
} | ||
|
||
result := make(map[string]interface{}) | ||
result["receipt"] = map[string]interface{}{ | ||
"message": string(ctrlr.Receipt.Message), | ||
} | ||
|
||
asJSON, _ := json.Marshal(result) | ||
fmt.Println(common.JSONPrettyFormat(string(asJSON))) | ||
return nil | ||
}, | ||
} | ||
|
||
return []*cobra.Command{cmdBalance, cmdActivate} | ||
} | ||
|
||
func init() { | ||
cmdAccount := &cobra.Command{ | ||
Use: "account", | ||
Short: "Check account balance", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
cmd.Help() | ||
return nil | ||
}, | ||
} | ||
|
||
cmdAccount.AddCommand(accountSub()...) | ||
RootCmd.AddCommand(cmdAccount) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/fbsobreira/gotron-sdk/pkg/common" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func assetsSub() []*cobra.Command { | ||
cmdIssue := &cobra.Command{ | ||
Use: "issue <ACCOUNT_NAME>", | ||
Short: "Check account balance", | ||
Long: "Query for the latest account balance given Address", | ||
Args: cobra.ExactArgs(1), | ||
PreRunE: validateAddress, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
acc, err := conn.GetAccount(addr.String()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if noPrettyOutput { | ||
fmt.Println(acc) | ||
return nil | ||
} | ||
|
||
result := make(map[string]interface{}) | ||
result["address"] = addr.String() | ||
result["type"] = acc.GetType() | ||
result["name"] = acc.GetAccountName() | ||
result["balance"] = float64(acc.GetBalance()) / 1000000 | ||
asJSON, _ := json.Marshal(result) | ||
fmt.Println(common.JSONPrettyFormat(string(asJSON))) | ||
return nil | ||
}, | ||
} | ||
|
||
return []*cobra.Command{cmdIssue} | ||
} | ||
|
||
func init() { | ||
cmdAssets := &cobra.Command{ | ||
Use: "assets", | ||
Short: "Assets Manager", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
cmd.Help() | ||
return nil | ||
}, | ||
} | ||
|
||
cmdAssets.AddCommand(assetsSub()...) | ||
RootCmd.AddCommand(cmdAssets) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
cmdCompletion := &cobra.Command{ | ||
Use: "completion", | ||
Short: "Generates bash completion scripts", | ||
Long: `To load completion, run: | ||
. <(tronctl completion) | ||
Add the line to your ~/.bashrc to enable completion for each bash session. | ||
`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
RootCmd.GenBashCompletion(os.Stdout) | ||
return nil | ||
}, | ||
} | ||
RootCmd.AddCommand(cmdCompletion) | ||
} |
Oops, something went wrong.