mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-09-15 05:50:10 +00:00
33 lines
1.3 KiB
Go
33 lines
1.3 KiB
Go
package rpchandlers
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/app/appmessage"
|
|
"github.com/kaspanet/kaspad/app/rpc/rpccontext"
|
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
|
"github.com/kaspanet/kaspad/domain/miningmanager/mempool"
|
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// HandleSubmitTransaction handles the respectively named RPC command
|
|
func HandleSubmitTransaction(context *rpccontext.Context, _ *router.Router, request appmessage.Message) (appmessage.Message, error) {
|
|
submitTransactionRequest := request.(*appmessage.SubmitTransactionRequestMessage)
|
|
|
|
domainTransaction := appmessage.MsgTxToDomainTransaction(submitTransactionRequest.Transaction)
|
|
transactionID := consensushashing.TransactionID(domainTransaction)
|
|
err := context.ProtocolManager.AddTransaction(domainTransaction)
|
|
if err != nil {
|
|
if !errors.As(err, &mempool.RuleError{}) {
|
|
return nil, err
|
|
}
|
|
|
|
log.Debugf("Rejected transaction %s: %s", transactionID, err)
|
|
errorMessage := &appmessage.SubmitTransactionResponseMessage{}
|
|
errorMessage.Error = appmessage.RPCErrorf("Rejected transaction %s: %s", transactionID, err)
|
|
return errorMessage, nil
|
|
}
|
|
|
|
response := appmessage.NewSubmitTransactionResponseMessage(transactionID.String())
|
|
return response, nil
|
|
}
|