mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-09 23:56:42 +00:00

* [NOD-275] Moved getBlockTemplate and related functionality to a separate file. * [NOD-275] Started moving handlers to separate files. * [NOD-275] Fixed merge errors. * [NOD-275] Moved all handlers out of rpcserver.go. * [NOD-275] Moved non-shared functions out of rpcserver.go. * [NOD-275] Moved handleGetAllManualNodesInfo to a separate file. * [NOD-275] Moved handlers out of rpcwebsocket.go to separate files. * [NOD-275] Fixed import error. * [NOD-275] Renamed all handler files to include underscores. * [NOD-275] Moved common rpc helper functions to common.go.
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package rpc
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/hex"
|
|
"github.com/daglabs/btcd/btcjson"
|
|
"github.com/daglabs/btcd/wire"
|
|
)
|
|
|
|
// handleDecodeRawTransaction handles decodeRawTransaction commands.
|
|
func handleDecodeRawTransaction(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
|
c := cmd.(*btcjson.DecodeRawTransactionCmd)
|
|
|
|
// Deserialize the transaction.
|
|
hexStr := c.HexTx
|
|
if len(hexStr)%2 != 0 {
|
|
hexStr = "0" + hexStr
|
|
}
|
|
serializedTx, err := hex.DecodeString(hexStr)
|
|
if err != nil {
|
|
return nil, rpcDecodeHexError(hexStr)
|
|
}
|
|
var mtx wire.MsgTx
|
|
err = mtx.Deserialize(bytes.NewReader(serializedTx))
|
|
if err != nil {
|
|
return nil, &btcjson.RPCError{
|
|
Code: btcjson.ErrRPCDeserialization,
|
|
Message: "TX decode failed: " + err.Error(),
|
|
}
|
|
}
|
|
|
|
// Create and return the result.
|
|
txReply := btcjson.TxRawDecodeResult{
|
|
TxID: mtx.TxID().String(),
|
|
Version: mtx.Version,
|
|
Locktime: mtx.LockTime,
|
|
Vin: createVinList(&mtx),
|
|
Vout: createVoutList(&mtx, s.cfg.DAGParams, nil),
|
|
}
|
|
return txReply, nil
|
|
}
|