mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-25 08:16:46 +00:00

* [NOD-1223] Delete unused files/packages. * [NOD-1223] Move signal and limits to the os package. * [NOD-1223] Put database and dbaccess into the db package. * [NOD-1223] Fold the logs package into the logger package. * [NOD-1223] Rename domainmessage to appmessage. * [NOD-1223] Rename to/from DomainMessage to AppMessage. * [NOD-1223] Move appmessage to the app packge. * [NOD-1223] Move protocol to the app packge. * [NOD-1223] Move the network package to the infrastructure packge. * [NOD-1223] Rename cmd to executables. * [NOD-1223] Fix go.doc in the logger package.
64 lines
2.0 KiB
Go
64 lines
2.0 KiB
Go
// Copyright (c) 2014-2017 The btcsuite developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package client
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
"github.com/kaspanet/kaspad/app/appmessage"
|
|
"github.com/kaspanet/kaspad/infrastructure/network/rpc/model"
|
|
"github.com/kaspanet/kaspad/util/daghash"
|
|
)
|
|
|
|
// FutureSendRawTransactionResult is a future promise to deliver the result
|
|
// of a SendRawTransactionAsync RPC invocation (or an applicable error).
|
|
type FutureSendRawTransactionResult chan *response
|
|
|
|
// Receive waits for the response promised by the future and returns the result
|
|
// of submitting the encoded transaction to the server which then relays it to
|
|
// the network.
|
|
func (r FutureSendRawTransactionResult) Receive() (*daghash.TxID, error) {
|
|
res, err := receiveFuture(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Unmarshal result as a string.
|
|
var txIDStr string
|
|
err = json.Unmarshal(res, &txIDStr)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return daghash.NewTxIDFromStr(txIDStr)
|
|
}
|
|
|
|
// SendRawTransactionAsync returns an instance of a type that can be used to get
|
|
// the result of the RPC at some future time by invoking the Receive function on
|
|
// the returned instance.
|
|
//
|
|
// See SendRawTransaction for the blocking version and more details.
|
|
func (c *Client) SendRawTransactionAsync(tx *appmessage.MsgTx, allowHighFees bool) FutureSendRawTransactionResult {
|
|
txHex := ""
|
|
if tx != nil {
|
|
// Serialize the transaction and convert to hex string.
|
|
buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
|
|
if err := tx.Serialize(buf); err != nil {
|
|
return newFutureError(err)
|
|
}
|
|
txHex = hex.EncodeToString(buf.Bytes())
|
|
}
|
|
|
|
cmd := model.NewSendRawTransactionCmd(txHex, &allowHighFees)
|
|
return c.sendCmd(cmd)
|
|
}
|
|
|
|
// SendRawTransaction submits the encoded transaction to the server which will
|
|
// then relay it to the network.
|
|
func (c *Client) SendRawTransaction(tx *appmessage.MsgTx, allowHighFees bool) (*daghash.TxID, error) {
|
|
return c.SendRawTransactionAsync(tx, allowHighFees).Receive()
|
|
}
|