cnct: add new methods for resolvers

This commit is contained in:
Joost Jager
2019-11-01 11:04:28 +01:00
parent 1e5eec990e
commit 32249cb72e
7 changed files with 102 additions and 98 deletions

View File

@@ -5,11 +5,12 @@ import (
"errors"
"io"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/invoices"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire"
)
// htlcIncomingContestResolver is a ContractResolver that's able to resolve an
@@ -34,6 +35,24 @@ type htlcIncomingContestResolver struct {
htlcSuccessResolver
}
// newIncomingContestResolver instantiates a new incoming htlc contest resolver.
func newIncomingContestResolver(htlcExpiry uint32,
circuitKey channeldb.CircuitKey, res lnwallet.IncomingHtlcResolution,
broadcastHeight uint32, payHash lntypes.Hash,
htlcAmt lnwire.MilliSatoshi,
resCfg ResolverConfig) *htlcIncomingContestResolver {
success := newSuccessResolver(
res, broadcastHeight, payHash, htlcAmt, resCfg,
)
return &htlcIncomingContestResolver{
htlcExpiry: htlcExpiry,
circuitKey: circuitKey,
htlcSuccessResolver: *success,
}
}
// Resolve attempts to resolve this contract. As we don't yet know of the
// preimage for the contract, we'll wait for one of two things to happen:
//
@@ -319,15 +338,6 @@ func newIncomingContestResolverFromReader(r io.Reader, resCfg ResolverConfig) (
return h, nil
}
// AttachConfig should be called once a resolved is successfully decoded from
// its stored format. This struct delivers the configuration items that
// resolvers need to complete their duty.
//
// NOTE: Part of the ContractResolver interface.
func (h *htlcIncomingContestResolver) AttachConfig(r ResolverConfig) {
h.htlcSuccessResolver.AttachConfig(r)
}
// A compile time assertion to ensure htlcIncomingContestResolver meets the
// ContractResolver interface.
var _ ContractResolver = (*htlcIncomingContestResolver)(nil)