m.Handle("/get-transaction", jsonHandler(a.getTransaction))
m.Handle("/list-transactions", jsonHandler(a.listTransactions))
- m.Handle("/get-txpool", jsonHandler(a.getChainTxPool))
+
+ m.Handle("/get-unconfirmed-transaction", jsonHandler(a.getUnconfirmedTx))
+ m.Handle("/list-unconfirmed-transactions", jsonHandler(a.listUnconformTxs))
m.Handle("/list-balances", jsonHandler(a.listBalances))
m.Handle("/list-unspent-outputs", jsonHandler(a.listUnspentOutputs))
log "github.com/sirupsen/logrus"
+ "encoding/hex"
"github.com/bytom/account"
"github.com/bytom/blockchain/query"
"github.com/bytom/consensus"
return NewSuccessResponse(transactions)
}
+// POST /get-unconfirmed-transaction
+func (a *API) getUnconfirmedTx(ctx context.Context, filter struct {
+ TxID string `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[:])
+
+ txHash := bc.NewHash(tmpTxID)
+ txPool := a.chain.GetTxPool()
+ txDesc, err := txPool.GetTransaction(&txHash)
+ if err != nil {
+ return NewErrorResponse(err)
+ }
+
+ tx := &BlockTx{
+ ID: txDesc.Tx.ID,
+ Version: txDesc.Tx.Version,
+ Size: txDesc.Tx.SerializedSize,
+ TimeRange: txDesc.Tx.TimeRange,
+ Inputs: []*query.AnnotatedInput{},
+ Outputs: []*query.AnnotatedOutput{},
+ StatusFail: false,
+ }
+
+ for i := range txDesc.Tx.Inputs {
+ tx.Inputs = append(tx.Inputs, a.wallet.BuildAnnotatedInput(txDesc.Tx, uint32(i)))
+ }
+ for i := range txDesc.Tx.Outputs {
+ tx.Outputs = append(tx.Outputs, a.wallet.BuildAnnotatedOutput(txDesc.Tx, i))
+ }
+
+ return NewSuccessResponse(tx)
+}
+
type getTxPoolResp struct {
TxID bc.Hash `json:"tx_id"`
}
-// POST /get-txpool
-func (a *API) getChainTxPool(ctx context.Context) Response {
+// POST /list-unconform-transactions
+func (a *API) listUnconformTxs(ctx context.Context) Response {
txIDs := []getTxPoolResp{}
txPool := a.chain.GetTxPool()
BytomcliCmd.AddCommand(getTransactionCmd)
BytomcliCmd.AddCommand(listTransactionsCmd)
+
+ BytomcliCmd.AddCommand(getUnconfirmedTransactionCmd)
+ BytomcliCmd.AddCommand(listUnconfirmedTransactionsCmd)
+
BytomcliCmd.AddCommand(listUnspentOutputsCmd)
BytomcliCmd.AddCommand(listBalancesCmd)
BytomcliCmd.AddCommand(submitTransactionCmd)
BytomcliCmd.AddCommand(estimateTransactionGasCmd)
BytomcliCmd.AddCommand(signSubTransactionCmd)
- BytomcliCmd.AddCommand(getTxPoolCmd)
BytomcliCmd.AddCommand(getBlockCountCmd)
BytomcliCmd.AddCommand(blockHashCmd)
},
}
-var getTxPoolCmd = &cobra.Command{
- Use: "get-txpool",
- Short: "get txpool transactions hashes",
- Args: cobra.NoArgs,
- Run: func(cmd *cobra.Command, args []string) {
- data, exitCode := util.ClientCall("/get-txpool")
- if exitCode != util.Success {
- os.Exit(exitCode)
- }
-
- printJSONList(data)
- },
-}
-
var getTransactionCmd = &cobra.Command{
Use: "get-transaction <hash>",
Short: "get the transaction by matching the given transaction hash",
},
}
+var getUnconfirmedTransactionCmd = &cobra.Command{
+ Use: "get-unconfirmed-transaction <hash>",
+ Short: "get unconfirmed transaction by matching the given transaction hash",
+ Args: cobra.ExactArgs(1),
+ Run: func(cmd *cobra.Command, args []string) {
+ txInfo := &struct {
+ TxID string `json:"tx_id"`
+ }{TxID: args[0]}
+
+ data, exitCode := util.ClientCall("/get-unconfirmed-transaction", txInfo)
+ if exitCode != util.Success {
+ os.Exit(exitCode)
+ }
+
+ printJSON(data)
+ },
+}
+
+var listUnconfirmedTransactionsCmd = &cobra.Command{
+ Use: "list-unconfirmed-transactions",
+ Short: "list unconfirmed transactions hashes",
+ Args: cobra.NoArgs,
+ Run: func(cmd *cobra.Command, args []string) {
+ data, exitCode := util.ClientCall("/list-unconfirmed-transactions")
+ if exitCode != util.Success {
+ os.Exit(exitCode)
+ }
+
+ printJSONList(data)
+ },
+}
+
var gasRateCmd = &cobra.Command{
Use: "gas-rate",
Short: "Print the current gas rate",