m.Handle("/get-unconfirmed-transaction", jsonHandler(a.getUnconfirmedTx))
m.Handle("/list-unconfirmed-transactions", jsonHandler(a.listUnconfirmedTxs))
+ m.Handle("/get-raw-transaction", jsonHandler(a.getRawTransaction))
m.Handle("/get-block-hash", jsonHandler(a.getBestBlockHash))
m.Handle("/get-block-header", jsonHandler(a.getBlockHeader))
"github.com/bytom/consensus"
chainjson "github.com/bytom/encoding/json"
"github.com/bytom/protocol/bc"
+ "github.com/bytom/protocol/bc/types"
)
// POST /list-accounts
})
}
+// RawTx is the tx struct for getRawTransaction
+type RawTx struct {
+ Version uint64 `json:"version"`
+ Size uint64 `json:"size"`
+ TimeRange uint64 `json:"time_range"`
+ Inputs []*query.AnnotatedInput `json:"inputs"`
+ Outputs []*query.AnnotatedOutput `json:"outputs"`
+}
+
+// POST /get-transaction-template
+func (a *API) getRawTransaction(ctx context.Context, ins struct {
+ Tx types.Tx `json:"raw_transaction"`
+}) Response {
+ tx := &RawTx{
+ Version: ins.Tx.Version,
+ Size: ins.Tx.SerializedSize,
+ TimeRange: ins.Tx.TimeRange,
+ Inputs: []*query.AnnotatedInput{},
+ Outputs: []*query.AnnotatedOutput{},
+ }
+
+ for i := range ins.Tx.Inputs {
+ tx.Inputs = append(tx.Inputs, a.wallet.BuildAnnotatedInput(&ins.Tx, uint32(i)))
+ }
+ for i := range ins.Tx.Outputs {
+ tx.Outputs = append(tx.Outputs, a.wallet.BuildAnnotatedOutput(&ins.Tx, i))
+ }
+
+ return NewSuccessResponse(tx)
+}
+
// POST /list-unspent-outputs
func (a *API) listUnspentOutputs(ctx context.Context, filter struct {
ID string `json:"id"`
},
}
+var getRawTransactionCmd = &cobra.Command{
+ Use: "get-raw-transaction <raw_transaction>",
+ Short: "get the transaction by raw_transaction",
+ Args: cobra.ExactArgs(1),
+ Run: func(cmd *cobra.Command, args []string) {
+ var ins = struct {
+ Tx types.Tx `json:"raw_transaction"`
+ }{}
+
+ err := json.Unmarshal([]byte(args[0]), &ins)
+ if err != nil {
+ jww.ERROR.Println(err)
+ os.Exit(util.ErrLocalExe)
+ }
+
+ data, exitCode := util.ClientCall("/get-raw-transaction", &ins)
+ if exitCode != util.Success {
+ os.Exit(exitCode)
+ }
+
+ printJSON(data)
+ },
+}
+
var getTransactionCmd = &cobra.Command{
Use: "get-transaction <hash>",
Short: "get the transaction by matching the given transaction hash",