-
Notifications
You must be signed in to change notification settings - Fork 64
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 #598 from TRON-US/v1.3.4-release
v1.3.4 release
- Loading branch information
Showing
9 changed files
with
276 additions
and
89 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
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
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
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,127 @@ | ||
package commands | ||
|
||
import ( | ||
"encoding/hex" | ||
"strconv" | ||
|
||
cmds "github.com/TRON-US/go-btfs-cmds" | ||
"github.com/TRON-US/go-btfs/core/commands/cmdenv" | ||
"github.com/TRON-US/go-btfs/core/wallet" | ||
"github.com/gogo/protobuf/proto" | ||
) | ||
|
||
var TronCmd = &cmds.Command{ | ||
Helptext: cmds.HelpText{ | ||
Tagline: "BTFS tron", | ||
ShortDescription: `'btfs tron' is a set of commands to forward requests to trongrid node.`, | ||
LongDescription: `'btfs tron' is a set of commands to forward requests to trongrid node.`, | ||
}, | ||
|
||
Subcommands: map[string]*cmds.Command{ | ||
"prepare": prepareCmd, | ||
"send": sendCmd, | ||
"status": statusCmd, | ||
}, | ||
} | ||
|
||
var prepareCmd = &cmds.Command{ | ||
Helptext: cmds.HelpText{ | ||
Tagline: "prepare transaction", | ||
ShortDescription: "prepare transaction", | ||
}, | ||
Arguments: []cmds.Argument{ | ||
cmds.StringArg("from", true, false, "address for the token transfer from."), | ||
cmds.StringArg("to", true, false, "address for the token transfer to."), | ||
cmds.StringArg("amount", true, false, "amount of µBTT (=0.000001BTT) to transfer."), | ||
}, | ||
Options: []cmds.Option{}, | ||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { | ||
n, err := cmdenv.GetNode(env) | ||
if err != nil { | ||
return err | ||
} | ||
cfg, err := n.Repo.Config() | ||
if err != nil { | ||
return err | ||
} | ||
amount, err := strconv.ParseInt(req.Arguments[2], 10, 64) | ||
if err != nil { | ||
return err | ||
} | ||
tx, err := wallet.PrepareTx(req.Context, cfg, req.Arguments[0], req.Arguments[1], amount) | ||
if err != nil { | ||
return err | ||
} | ||
rawBytes, err := proto.Marshal(tx.Transaction.RawData) | ||
if err != nil { | ||
return err | ||
} | ||
return cmds.EmitOnce(res, &TxResult{ | ||
TxId: hex.EncodeToString(tx.Txid), | ||
Raw: hex.EncodeToString(rawBytes), | ||
}) | ||
}, | ||
Type: &TxResult{}, | ||
} | ||
|
||
type TxResult struct { | ||
TxId string | ||
Raw string | ||
} | ||
|
||
var sendCmd = &cmds.Command{ | ||
Helptext: cmds.HelpText{ | ||
Tagline: "send raw transaction", | ||
ShortDescription: "send raw transaction", | ||
}, | ||
Arguments: []cmds.Argument{ | ||
cmds.StringArg("raw", true, false, "raw transaction in hex"), | ||
cmds.StringArg("sig", true, false, "sig of raw transaction in hex"), | ||
}, | ||
Options: []cmds.Option{}, | ||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { | ||
n, err := cmdenv.GetNode(env) | ||
if err != nil { | ||
return err | ||
} | ||
cfg, err := n.Repo.Config() | ||
if err != nil { | ||
return err | ||
} | ||
rawBytes, err := hex.DecodeString(req.Arguments[0]) | ||
if err != nil { | ||
return err | ||
} | ||
sigBytes, err := hex.DecodeString(req.Arguments[1]) | ||
if err != nil { | ||
return err | ||
} | ||
return wallet.SendRawTransaction(req.Context, cfg.Services.FullnodeDomain, rawBytes, sigBytes) | ||
}, | ||
} | ||
|
||
var statusCmd = &cmds.Command{ | ||
Helptext: cmds.HelpText{ | ||
Tagline: "get status of tx", | ||
ShortDescription: "get status of tx", | ||
}, | ||
Arguments: []cmds.Argument{ | ||
cmds.StringArg("txId", true, false, "transaction id"), | ||
}, | ||
Options: []cmds.Option{}, | ||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { | ||
n, err := cmdenv.GetNode(env) | ||
if err != nil { | ||
return err | ||
} | ||
cfg, err := n.Repo.Config() | ||
if err != nil { | ||
return err | ||
} | ||
status, err := wallet.GetStatus(req.Context, cfg.Services.SolidityDomain, req.Arguments[0]) | ||
if err != nil { | ||
return err | ||
} | ||
return cmds.EmitOnce(res, map[string]string{"status": status}) | ||
}, | ||
} |
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
Oops, something went wrong.