m.Handle("/list-transactions", jsonHandler(a.listTransactions))
m.Handle("/get-unconfirmed-transaction", jsonHandler(a.getUnconfirmedTx))
- m.Handle("/list-unconfirmed-transactions", jsonHandler(a.listUnconformTxs))
+ m.Handle("/list-unconfirmed-transactions", jsonHandler(a.listUnconfirmedTxs))
m.Handle("/list-balances", jsonHandler(a.listBalances))
m.Handle("/list-unspent-outputs", jsonHandler(a.listUnspentOutputs))
import (
"context"
- "encoding/hex"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/bytom/account"
"github.com/bytom/blockchain/query"
"github.com/bytom/consensus"
+ chainjson "github.com/bytom/encoding/json"
"github.com/bytom/protocol/bc"
)
// POST /get-unconfirmed-transaction
func (a *API) getUnconfirmedTx(ctx context.Context, filter struct {
- TxID string `json:"tx_id"`
+ TxID chainjson.HexBytes `json:"tx_id"`
}) Response {
- txID, err := hex.DecodeString(filter.TxID)
- if err != nil {
- log.Errorf("convert txID[%s] string to byte err: %v", filter.TxID, err)
- return NewErrorResponse(err)
- }
-
var tmpTxID [32]byte
- copy(tmpTxID[:], txID[:])
+ copy(tmpTxID[:], filter.TxID[:])
txHash := bc.NewHash(tmpTxID)
txPool := a.chain.GetTxPool()
return NewSuccessResponse(tx)
}
-type getTxPoolResp struct {
- TxID bc.Hash `json:"tx_id"`
-}
-
// POST /list-unconform-transactions
-func (a *API) listUnconformTxs(ctx context.Context) Response {
- txIDs := []getTxPoolResp{}
+func (a *API) listUnconfirmedTxs(ctx context.Context) Response {
+ txIDs := []bc.Hash{}
txPool := a.chain.GetTxPool()
txs := txPool.GetTransactions()
for _, txDesc := range txs {
- txIDs = append(txIDs, getTxPoolResp{TxID: bc.Hash(txDesc.Tx.ID)})
+ txIDs = append(txIDs, bc.Hash(txDesc.Tx.ID))
}
return NewSuccessResponse(txIDs)
package commands
import (
+ "encoding/hex"
"encoding/json"
"fmt"
"os"
"github.com/bytom/api"
"github.com/bytom/blockchain/txbuilder"
+ chainjson "github.com/bytom/encoding/json"
"github.com/bytom/protocol/bc/types"
"github.com/bytom/util"
)
Short: "get unconfirmed transaction by matching the given transaction hash",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
+ txID, err := hex.DecodeString(args[0])
+ if err != nil {
+ jww.ERROR.Println(err)
+ os.Exit(util.ErrLocalExe)
+ }
+
txInfo := &struct {
- TxID string `json:"tx_id"`
- }{TxID: args[0]}
+ TxID chainjson.HexBytes `json:"tx_id"`
+ }{TxID: txID}
data, exitCode := util.ClientCall("/get-unconfirmed-transaction", txInfo)
if exitCode != util.Success {