diff --git a/client/asset/interface.go b/client/asset/interface.go index 25ac8c2477..8dc96fefec 100644 --- a/client/asset/interface.go +++ b/client/asset/interface.go @@ -458,9 +458,17 @@ type TxFeeEstimator interface { EstimateSendTxFee(address string, value, feeRate uint64, subtract bool) (fee uint64, isValidAddress bool, err error) } +// Broadcaster is a wallet that can send a raw transaction on the asset network. +type Broadcaster interface { + // SendTransaction broadcasts a raw transaction, returning its coin ID. + SendTransaction(rawTx []byte) ([]byte, error) +} + // Bonder is a wallet capable of creating and redeeming time-locked fidelity // bond transaction outputs. type Bonder interface { + Broadcaster + // MakeBondTx authors a DEX time-locked fidelity bond transaction for the // provided amount, lock time, and dex account ID. An explicit private key // type is used to guarantee it's not bytes from something else like a @@ -469,8 +477,6 @@ type Bonder interface { // RefundBond will refund the bond given the full bond output details and // private key to spend it. RefundBond(ctx context.Context, ver uint16, coinID, script []byte, amt uint64, privKey *secp256k1.PrivateKey) ([]byte, error) - // SendTransaction broadcasts a raw transaction, returning its coin ID. - SendTransaction(rawTx []byte) ([]byte, error) // A RefundBondByCoinID may be created in the future to attempt to refund a // bond by locating it on chain, i.e. without providing the amount or diff --git a/client/core/wallet.go b/client/core/wallet.go index 4acd9014e2..ceb632c003 100644 --- a/client/core/wallet.go +++ b/client/core/wallet.go @@ -466,10 +466,11 @@ func (w *xcWallet) RefundBond(ctx context.Context, ver uint16, coinID, script [] return bonder.RefundBond(ctx, ver, coinID, script, amt, priv) } +// SendTransaction broadcasts a raw transaction if the wallet is a Broadcaster. func (w *xcWallet) SendTransaction(tx []byte) ([]byte, error) { - bonder, ok := w.Wallet.(asset.Bonder) + bonder, ok := w.Wallet.(asset.Broadcaster) if !ok { - return nil, errors.New("wallet does not implement SendTransaction") // seems silly, I know, but Bonder is optional + return nil, errors.New("wallet is not a Broadcaster") } return bonder.SendTransaction(tx) }