input: add constructor for csv-locked inputs
This commit is contained in:
parent
55a32c951a
commit
7e472c9e8c
@ -48,6 +48,7 @@ type inputKit struct {
|
|||||||
witnessType WitnessType
|
witnessType WitnessType
|
||||||
signDesc SignDescriptor
|
signDesc SignDescriptor
|
||||||
heightHint uint32
|
heightHint uint32
|
||||||
|
blockToMaturity uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
// OutPoint returns the breached output's identifier that is to be included as
|
// OutPoint returns the breached output's identifier that is to be included as
|
||||||
@ -74,6 +75,13 @@ func (i *inputKit) HeightHint() uint32 {
|
|||||||
return i.heightHint
|
return i.heightHint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BlocksToMaturity returns the relative timelock, as a number of blocks, that
|
||||||
|
// must be built on top of the confirmation height before the output can be
|
||||||
|
// spent. For non-CSV locked inputs this is always zero.
|
||||||
|
func (i *inputKit) BlocksToMaturity() uint32 {
|
||||||
|
return i.blockToMaturity
|
||||||
|
}
|
||||||
|
|
||||||
// BaseInput contains all the information needed to sweep a basic output
|
// BaseInput contains all the information needed to sweep a basic output
|
||||||
// (CSV/CLTV/no time lock)
|
// (CSV/CLTV/no time lock)
|
||||||
type BaseInput struct {
|
type BaseInput struct {
|
||||||
@ -107,6 +115,23 @@ func NewBaseInput(outpoint *wire.OutPoint, witnessType WitnessType,
|
|||||||
return &input
|
return &input
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCsvInput assembles a new csv-locked input that can be used to
|
||||||
|
// construct a sweep transaction.
|
||||||
|
func NewCsvInput(outpoint *wire.OutPoint, witnessType WitnessType,
|
||||||
|
signDescriptor *SignDescriptor, heightHint uint32,
|
||||||
|
blockToMaturity uint32) *BaseInput {
|
||||||
|
|
||||||
|
return &BaseInput{
|
||||||
|
inputKit{
|
||||||
|
outpoint: *outpoint,
|
||||||
|
witnessType: witnessType,
|
||||||
|
signDesc: *signDescriptor,
|
||||||
|
heightHint: heightHint,
|
||||||
|
blockToMaturity: blockToMaturity,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CraftInputScript returns a valid set of input scripts allowing this output
|
// CraftInputScript returns a valid set of input scripts allowing this output
|
||||||
// to be spent. The returned input scripts should target the input at location
|
// to be spent. The returned input scripts should target the input at location
|
||||||
// txIndex within the passed transaction. The input scripts generated by this
|
// txIndex within the passed transaction. The input scripts generated by this
|
||||||
@ -119,13 +144,6 @@ func (bi *BaseInput) CraftInputScript(signer Signer, txn *wire.MsgTx,
|
|||||||
return witnessFunc(txn, hashCache, txinIdx)
|
return witnessFunc(txn, hashCache, txinIdx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlocksToMaturity returns the relative timelock, as a number of blocks, that
|
|
||||||
// must be built on top of the confirmation height before the output can be
|
|
||||||
// spent. For non-CSV locked inputs this is always zero.
|
|
||||||
func (bi *BaseInput) BlocksToMaturity() uint32 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// HtlcSucceedInput constitutes a sweep input that needs a pre-image. The input
|
// HtlcSucceedInput constitutes a sweep input that needs a pre-image. The input
|
||||||
// is expected to reside on the commitment tx of the remote party and should
|
// is expected to reside on the commitment tx of the remote party and should
|
||||||
// not be a second level tx output.
|
// not be a second level tx output.
|
||||||
@ -175,13 +193,6 @@ func (h *HtlcSucceedInput) CraftInputScript(signer Signer, txn *wire.MsgTx,
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlocksToMaturity returns the relative timelock, as a number of blocks, that
|
|
||||||
// must be built on top of the confirmation height before the output can be
|
|
||||||
// spent.
|
|
||||||
func (h *HtlcSucceedInput) BlocksToMaturity() uint32 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compile-time constraints to ensure each input struct implement the Input
|
// Compile-time constraints to ensure each input struct implement the Input
|
||||||
// interface.
|
// interface.
|
||||||
var _ Input = (*BaseInput)(nil)
|
var _ Input = (*BaseInput)(nil)
|
||||||
|
Loading…
Reference in New Issue
Block a user