Skip to content

Commit

Permalink
Merge pull request #598 from TRON-US/v1.3.4-release
Browse files Browse the repository at this point in the history
v1.3.4 release
  • Loading branch information
Eric Chen committed Jul 24, 2020
2 parents f11869f + 8b6f25e commit 46772a3
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 89 deletions.
4 changes: 4 additions & 0 deletions core/commands/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ func TestCommands(t *testing.T) {
"/wallet/transactions",
"/wallet/transfer",
"/wallet/import",
"/tron",
"/tron/prepare",
"/tron/send",
"/tron/status",
}

cmdSet := make(map[string]struct{})
Expand Down
11 changes: 7 additions & 4 deletions core/commands/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ And if specified a new btfs path, it will be applied.
Options: []cmds.Option{
cmds.BoolOption(postPathModificationName, "p", "post path modification").WithDefault(false),
}, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
daemonCmd := exec.Command(path.Excutable, "daemon")
shutdownCmd := exec.Command(path.Excutable, "shutdown")
if err := shutdownCmd.Run(); err != nil {
return err
}

if req.Options[postPathModificationName].(bool) && path.StorePath != "" && path.OriginPath != "" {
if err := path.MoveFolder(); err != nil {
return err
Expand All @@ -44,10 +48,9 @@ And if specified a new btfs path, it will be applied.
if err := path.WriteProperties(); err != nil {
return err
}

daemonCmd.Env = os.Environ()
daemonCmd.Env = append(daemonCmd.Env, "BTFS_PATH="+path.StorePath)
}

daemonCmd := exec.Command(path.Excutable, "daemon")
if err := daemonCmd.Start(); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions core/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ var rootSubcommands = map[string]*cmds.Command{
"metadata": MetadataCmd,
"guard": GuardCmd,
"wallet": WalletCmd,
"tron": TronCmd,
//"update": ExternalBinary(),
}

Expand Down
127 changes: 127 additions & 0 deletions core/commands/tron.go
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})
},
}
36 changes: 20 additions & 16 deletions core/wallet/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ func ConfirmDepositProcess(ctx context.Context, n *core.IpfsNode, prepareRespons
log.Debug(fmt.Sprintf("[Id:%d] ConfirmDepositProcess begin.", prepareResponse.GetId()))

// Continuous call ConfirmDeposit until it responses a FAILED or SUCCESS.
for time.Now().UnixNano()/1e6 < (prepareResponse.GetTronTransaction().GetRawData().GetExpiration() + 240*1000) {
time.Sleep(10 * time.Second)
for time.Now().UnixNano()/1e6 < (prepareResponse.GetTronTransaction().GetRawData().GetExpiration() + 480*1000) {
time.Sleep(5 * time.Second)

// ConfirmDeposit after 1min, because watcher need wait for 1min to confirm tron transaction.
if time.Now().UnixNano()/1e6 < (prepareResponse.GetTronTransaction().GetRawData().GetTimestamp() + 60*1000) {
Expand Down Expand Up @@ -168,28 +168,32 @@ func ConfirmDepositProcess(ctx context.Context, n *core.IpfsNode, prepareRespons
return err
}
signSuccessChannelState.ToSignature = toSignature

err = UpdateStatus(n.Repo.Datastore(), n.Identity.Pretty(), txId, StatusSuccess)
if err != nil {
return err
}
} else {
return fmt.Errorf("[Id:%d] SignSuccessChannelState is nil", prepareResponse.GetId())
}

err = grpc.EscrowClient(escrowService).WithContext(ctx,
func(ctx context.Context, client escrowPb.EscrowServiceClient) error {
_, err = client.CloseChannel(ctx, signSuccessChannelState)
if err != nil {
return err
}
return nil
})
for i := 0; i < 10; i++ {
err = grpc.EscrowClient(escrowService).WithContext(ctx,
func(ctx context.Context, client escrowPb.EscrowServiceClient) error {
_, err = client.CloseChannel(ctx, signSuccessChannelState)
if err != nil {
return err
}
return nil
})
if err == nil {
break
}
time.Sleep(5 * time.Second)
}
if err != nil {
return err
}

log.Info(fmt.Sprintf("[Id:%d] Close SuccessChannelState succeed.", prepareResponse.GetId()))
err = UpdateStatus(n.Repo.Datastore(), n.Identity.Pretty(), txId, StatusSuccess)
if err != nil {
return err
}
return nil
}
}
Expand Down

0 comments on commit 46772a3

Please sign in to comment.