OSDN Git Service

Added a example about submit-transaction call.
authorgguoss <1536310027@qq.com>
Sat, 9 Sep 2017 09:02:09 +0000 (17:02 +0800)
committergguoss <1536310027@qq.com>
Sat, 9 Sep 2017 09:02:09 +0000 (17:02 +0800)
blockchain/reactor.go
blockchain/transact.go
cmd/bytomcli/example/issue.go

index 7d81104..021c350 100644 (file)
@@ -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 {
index 7fb73fd..0a7f558 100644 (file)
@@ -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
        }
index eff8056..c9e1853 100644 (file)
@@ -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)
 }