From 593603abaeaeff3b13a145e4a8c84511ea95bda3 Mon Sep 17 00:00:00 2001 From: gguoss <1536310027@qq.com> Date: Sat, 9 Sep 2017 17:02:09 +0800 Subject: [PATCH] Added a example about submit-transaction call. --- blockchain/reactor.go | 1 + blockchain/transact.go | 11 ++++------- cmd/bytomcli/example/issue.go | 8 ++++++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/blockchain/reactor.go b/blockchain/reactor.go index 7d811047..021c3502 100644 --- a/blockchain/reactor.go +++ b/blockchain/reactor.go @@ -163,6 +163,7 @@ func (bcr *BlockchainReactor) BuildHander() { m.Handle("/", alwaysError(errors.New("not Found"))) m.Handle("/info", jsonHandler(bcr.info)) m.Handle("/create-block-key", jsonHandler(bcr.createblockkey)) + m.Handle("/submit-transaction", jsonHandler(bcr.submit)) latencyHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { if l := latency(m, req); l != nil { diff --git a/blockchain/transact.go b/blockchain/transact.go index 7fb73fda..0a7f5583 100644 --- a/blockchain/transact.go +++ b/blockchain/transact.go @@ -6,14 +6,11 @@ import ( "sync" "time" - //"github.com/bytom/blockchain/fetch" "github.com/bytom/blockchain/txbuilder" chainjson "github.com/bytom/encoding/json" "github.com/bytom/errors" - //"github.com/bytom/log" "github.com/bytom/net/http/httperror" "github.com/bytom/net/http/reqid" - //"github.com/bytom/protocol/bc" "github.com/bytom/protocol/bc/legacy" ) @@ -282,16 +279,16 @@ func (a *BlockchainReactor) waitForTxInBlock(ctx context.Context, tx *legacy.Tx, } } -type submitArg struct { +type SubmitArg struct { Transactions []txbuilder.Template - wait chainjson.Duration + Wait chainjson.Duration WaitUntil string `json:"wait_until"` // values none, confirmed, processed. default: processed } // POST /submit-transaction -func (a *BlockchainReactor) submit(ctx context.Context, x submitArg) (interface{}, error) { +func (a *BlockchainReactor) submit(ctx context.Context, x SubmitArg) (interface{}, error) { // Setup a timeout for the provided wait duration. - timeout := x.wait.Duration + timeout := x.Wait.Duration if timeout <= 0 { timeout = 30 * time.Second } diff --git a/cmd/bytomcli/example/issue.go b/cmd/bytomcli/example/issue.go index eff8056b..c9e18539 100644 --- a/cmd/bytomcli/example/issue.go +++ b/cmd/bytomcli/example/issue.go @@ -3,6 +3,7 @@ package example import ( "context" "fmt" + "time" stdjson "encoding/json" "github.com/bytom/blockchain/rpc" @@ -10,6 +11,7 @@ import ( "github.com/bytom/blockchain/query" "github.com/bytom/blockchain/txbuilder" bc "github.com/bytom/blockchain" + "github.com/bytom/encoding/json" ) // TO DO: issue a asset to a account. @@ -93,4 +95,10 @@ func IssueTest(client *rpc.Client, args []string) { fmt.Printf("sign tpl:%v\n", tpl[0]) fmt.Printf("sign tpl's SigningInstructions:%v\n", tpl[0].SigningInstructions[0]) fmt.Printf("SigningInstructions's SignatureWitnesses:%v\n", tpl[0].SigningInstructions[0].SignatureWitnesses[0]) + + // submit-transaction + var submitResponse interface{} + submitArg := bc.SubmitArg{tpl, json.Duration{time.Duration(1000000)}, "none"} + client.Call(context.Background(), "/submit-transaction", submitArg, &submitResponse) + fmt.Printf("submit transaction:%v\n", submitResponse) } -- 2.11.0