Skip to content

Commit

Permalink
fixup client/asset
Browse files Browse the repository at this point in the history
  • Loading branch information
chappjc committed Nov 28, 2022
1 parent 0e34aa5 commit 3de34ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 8 additions & 2 deletions client/asset/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions client/core/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 3de34ca

Please sign in to comment.