2019-01-16 17:47:43 +03:00
|
|
|
package input
|
2017-05-07 14:04:28 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2018-06-05 04:34:16 +03:00
|
|
|
"github.com/btcsuite/btcd/txscript"
|
|
|
|
"github.com/btcsuite/btcd/wire"
|
2017-05-07 14:04:28 +03:00
|
|
|
)
|
|
|
|
|
2019-10-07 14:41:46 +03:00
|
|
|
// WitnessGenerator represents a function that is able to generate the final
|
|
|
|
// witness for a particular public key script. Additionally, if required, this
|
|
|
|
// function will also return the sigScript for spending nested P2SH witness
|
|
|
|
// outputs. This function acts as an abstraction layer, hiding the details of
|
|
|
|
// the underlying script.
|
|
|
|
type WitnessGenerator func(tx *wire.MsgTx, hc *txscript.TxSigHashes,
|
|
|
|
inputIndex int) (*Script, error)
|
|
|
|
|
|
|
|
// WitnessType determines how an output's witness will be generated. This
|
|
|
|
// interface can be implemented to be used for custom sweep scripts if the
|
|
|
|
// pre-defined StandardWitnessType list doesn't provide a suitable one.
|
|
|
|
type WitnessType interface {
|
|
|
|
// String returns a human readable version of the WitnessType.
|
|
|
|
String() string
|
|
|
|
|
|
|
|
// WitnessGenerator will return a WitnessGenerator function that an
|
|
|
|
// output uses to generate the witness and optionally the sigScript for
|
|
|
|
// a sweep transaction.
|
|
|
|
WitnessGenerator(signer Signer,
|
|
|
|
descriptor *SignDescriptor) WitnessGenerator
|
|
|
|
|
|
|
|
// SizeUpperBound returns the maximum length of the witness of this
|
|
|
|
// WitnessType if it would be included in a tx. It also returns if the
|
|
|
|
// output itself is a nested p2sh output, if so then we need to take
|
|
|
|
// into account the extra sigScript data size.
|
|
|
|
SizeUpperBound() (int, bool, error)
|
|
|
|
|
|
|
|
// AddWeightEstimation adds the estimated size of the witness in bytes
|
2019-10-23 14:00:25 +03:00
|
|
|
// to the given weight estimator.
|
|
|
|
AddWeightEstimation(e *TxWeightEstimator) error
|
2019-10-07 14:41:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// StandardWitnessType is a numeric representation of standard pre-defined types
|
|
|
|
// of witness configurations.
|
|
|
|
type StandardWitnessType uint16
|
|
|
|
|
|
|
|
// A compile time check to ensure StandardWitnessType implements the
|
|
|
|
// WitnessType interface.
|
|
|
|
var _ WitnessType = (StandardWitnessType)(0)
|
2017-05-07 14:04:28 +03:00
|
|
|
|
|
|
|
const (
|
2020-03-06 18:11:46 +03:00
|
|
|
// CommitmentTimeLock is a witness that allows us to spend our output
|
|
|
|
// on our local commitment transaction after a relative lock-time
|
|
|
|
// lockout.
|
2019-10-07 14:41:46 +03:00
|
|
|
CommitmentTimeLock StandardWitnessType = 0
|
2017-05-07 14:04:28 +03:00
|
|
|
|
2017-10-02 06:54:23 +03:00
|
|
|
// CommitmentNoDelay is a witness that allows us to spend a settled
|
|
|
|
// no-delay output immediately on a counterparty's commitment
|
|
|
|
// transaction.
|
2019-10-07 14:41:46 +03:00
|
|
|
CommitmentNoDelay StandardWitnessType = 1
|
2017-05-07 14:04:28 +03:00
|
|
|
|
2017-10-02 06:54:23 +03:00
|
|
|
// CommitmentRevoke is a witness that allows us to sweep the settled
|
|
|
|
// output of a malicious counterparty's who broadcasts a revoked
|
|
|
|
// commitment transaction.
|
2019-10-07 14:41:46 +03:00
|
|
|
CommitmentRevoke StandardWitnessType = 2
|
2017-09-06 23:39:45 +03:00
|
|
|
|
2018-01-17 04:59:43 +03:00
|
|
|
// HtlcOfferedRevoke is a witness that allows us to sweep an HTLC which
|
|
|
|
// we offered to the remote party in the case that they broadcast a
|
2018-02-07 06:11:11 +03:00
|
|
|
// revoked commitment state.
|
2019-10-07 14:41:46 +03:00
|
|
|
HtlcOfferedRevoke StandardWitnessType = 3
|
2017-09-06 23:39:45 +03:00
|
|
|
|
|
|
|
// HtlcAcceptedRevoke is a witness that allows us to sweep an HTLC
|
2018-01-17 04:59:43 +03:00
|
|
|
// output sent to us in the case that the remote party broadcasts a
|
|
|
|
// revoked commitment state.
|
2019-10-07 14:41:46 +03:00
|
|
|
HtlcAcceptedRevoke StandardWitnessType = 4
|
2017-10-02 06:54:23 +03:00
|
|
|
|
2018-01-17 04:59:43 +03:00
|
|
|
// HtlcOfferedTimeoutSecondLevel is a witness that allows us to sweep
|
|
|
|
// an HTLC output that we extended to a party, but was never fulfilled.
|
|
|
|
// This HTLC output isn't directly on the commitment transaction, but
|
|
|
|
// is the result of a confirmed second-level HTLC transaction. As a
|
|
|
|
// result, we can only spend this after a CSV delay.
|
2019-10-07 14:41:46 +03:00
|
|
|
HtlcOfferedTimeoutSecondLevel StandardWitnessType = 5
|
2018-01-17 04:59:43 +03:00
|
|
|
|
|
|
|
// HtlcAcceptedSuccessSecondLevel is a witness that allows us to sweep
|
|
|
|
// an HTLC output that was offered to us, and for which we have a
|
2018-02-07 06:11:11 +03:00
|
|
|
// payment preimage. This HTLC output isn't directly on our commitment
|
2018-01-17 04:59:43 +03:00
|
|
|
// transaction, but is the result of confirmed second-level HTLC
|
|
|
|
// transaction. As a result, we can only spend this after a CSV delay.
|
2019-10-07 14:41:46 +03:00
|
|
|
HtlcAcceptedSuccessSecondLevel StandardWitnessType = 6
|
2018-01-17 04:59:43 +03:00
|
|
|
|
|
|
|
// HtlcOfferedRemoteTimeout is a witness that allows us to sweep an
|
|
|
|
// HTLC that we offered to the remote party which lies in the
|
|
|
|
// commitment transaction of the remote party. We can spend this output
|
|
|
|
// after the absolute CLTV timeout of the HTLC as passed.
|
2019-10-07 14:41:46 +03:00
|
|
|
HtlcOfferedRemoteTimeout StandardWitnessType = 7
|
2018-01-17 04:59:43 +03:00
|
|
|
|
|
|
|
// HtlcAcceptedRemoteSuccess is a witness that allows us to sweep an
|
|
|
|
// HTLC that was offered to us by the remote party. We use this witness
|
|
|
|
// in the case that the remote party goes to chain, and we know the
|
|
|
|
// pre-image to the HTLC. We can sweep this without any additional
|
|
|
|
// timeout.
|
2019-10-07 14:41:46 +03:00
|
|
|
HtlcAcceptedRemoteSuccess StandardWitnessType = 8
|
2018-01-21 06:57:34 +03:00
|
|
|
|
|
|
|
// HtlcSecondLevelRevoke is a witness that allows us to sweep an HTLC
|
|
|
|
// from the remote party's commitment transaction in the case that the
|
|
|
|
// broadcast a revoked commitment, but then also immediately attempt to
|
|
|
|
// go to the second level to claim the HTLC.
|
2019-10-07 14:41:46 +03:00
|
|
|
HtlcSecondLevelRevoke StandardWitnessType = 9
|
2018-11-18 07:51:58 +03:00
|
|
|
|
|
|
|
// WitnessKeyHash is a witness type that allows us to spend a regular
|
|
|
|
// p2wkh output that's sent to an output which is under complete
|
|
|
|
// control of the backing wallet.
|
2019-10-07 14:41:46 +03:00
|
|
|
WitnessKeyHash StandardWitnessType = 10
|
2018-11-18 07:51:58 +03:00
|
|
|
|
|
|
|
// NestedWitnessKeyHash is a witness type that allows us to sweep an
|
|
|
|
// output that sends to a nested P2SH script that pays to a key solely
|
|
|
|
// under our control. The witness generated needs to include the
|
2019-10-07 14:41:46 +03:00
|
|
|
NestedWitnessKeyHash StandardWitnessType = 11
|
2019-08-01 06:02:52 +03:00
|
|
|
|
|
|
|
// CommitSpendNoDelayTweakless is similar to the CommitSpendNoDelay
|
|
|
|
// type, but it omits the tweak that randomizes the key we need to
|
|
|
|
// spend with a channel peer supplied set of randomness.
|
2019-10-07 14:41:46 +03:00
|
|
|
CommitSpendNoDelayTweakless StandardWitnessType = 12
|
2020-03-06 18:11:46 +03:00
|
|
|
|
|
|
|
// CommitmentToRemoteConfirmed is a witness that allows us to spend our
|
|
|
|
// output on the counterparty's commitment transaction after a
|
|
|
|
// confirmation.
|
|
|
|
CommitmentToRemoteConfirmed StandardWitnessType = 13
|
2020-03-10 15:23:17 +03:00
|
|
|
|
|
|
|
// CommitmentAnchor is a witness that allows us to spend our anchor on
|
|
|
|
// the commitment transaction.
|
|
|
|
CommitmentAnchor StandardWitnessType = 14
|
2017-05-07 14:04:28 +03:00
|
|
|
)
|
|
|
|
|
2019-10-07 14:41:46 +03:00
|
|
|
// String returns a human readable version of the target WitnessType.
|
|
|
|
//
|
|
|
|
// NOTE: This is part of the WitnessType interface.
|
|
|
|
func (wt StandardWitnessType) String() string {
|
2018-12-17 03:52:57 +03:00
|
|
|
switch wt {
|
|
|
|
case CommitmentTimeLock:
|
|
|
|
return "CommitmentTimeLock"
|
|
|
|
|
2020-03-06 18:11:46 +03:00
|
|
|
case CommitmentToRemoteConfirmed:
|
|
|
|
return "CommitmentToRemoteConfirmed"
|
|
|
|
|
2020-03-10 15:23:17 +03:00
|
|
|
case CommitmentAnchor:
|
|
|
|
return "CommitmentAnchor"
|
|
|
|
|
2018-12-17 03:52:57 +03:00
|
|
|
case CommitmentNoDelay:
|
|
|
|
return "CommitmentNoDelay"
|
|
|
|
|
2019-08-01 06:02:52 +03:00
|
|
|
case CommitSpendNoDelayTweakless:
|
|
|
|
return "CommitmentNoDelayTweakless"
|
|
|
|
|
2018-12-17 03:52:57 +03:00
|
|
|
case CommitmentRevoke:
|
|
|
|
return "CommitmentRevoke"
|
|
|
|
|
|
|
|
case HtlcOfferedRevoke:
|
|
|
|
return "HtlcOfferedRevoke"
|
|
|
|
|
|
|
|
case HtlcAcceptedRevoke:
|
|
|
|
return "HtlcAcceptedRevoke"
|
|
|
|
|
|
|
|
case HtlcOfferedTimeoutSecondLevel:
|
|
|
|
return "HtlcOfferedTimeoutSecondLevel"
|
|
|
|
|
|
|
|
case HtlcAcceptedSuccessSecondLevel:
|
|
|
|
return "HtlcAcceptedSuccessSecondLevel"
|
|
|
|
|
|
|
|
case HtlcOfferedRemoteTimeout:
|
|
|
|
return "HtlcOfferedRemoteTimeout"
|
|
|
|
|
|
|
|
case HtlcAcceptedRemoteSuccess:
|
|
|
|
return "HtlcAcceptedRemoteSuccess"
|
|
|
|
|
|
|
|
case HtlcSecondLevelRevoke:
|
|
|
|
return "HtlcSecondLevelRevoke"
|
|
|
|
|
2019-10-23 14:00:25 +03:00
|
|
|
case WitnessKeyHash:
|
|
|
|
return "WitnessKeyHash"
|
|
|
|
|
|
|
|
case NestedWitnessKeyHash:
|
|
|
|
return "NestedWitnessKeyHash"
|
|
|
|
|
2018-12-17 03:52:57 +03:00
|
|
|
default:
|
|
|
|
return fmt.Sprintf("Unknown WitnessType: %v", uint32(wt))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-07 14:41:46 +03:00
|
|
|
// WitnessGenerator will return a WitnessGenerator function that an output uses
|
2018-11-18 07:48:41 +03:00
|
|
|
// to generate the witness and optionally the sigScript for a sweep
|
|
|
|
// transaction. The sigScript will be generated if the witness type warrants
|
|
|
|
// one for spending, such as the NestedWitnessKeyHash witness type.
|
2019-10-07 14:41:46 +03:00
|
|
|
//
|
|
|
|
// NOTE: This is part of the WitnessType interface.
|
|
|
|
func (wt StandardWitnessType) WitnessGenerator(signer Signer,
|
2017-05-07 14:04:28 +03:00
|
|
|
descriptor *SignDescriptor) WitnessGenerator {
|
|
|
|
|
|
|
|
return func(tx *wire.MsgTx, hc *txscript.TxSigHashes,
|
2019-01-16 17:47:43 +03:00
|
|
|
inputIndex int) (*Script, error) {
|
2017-05-07 14:04:28 +03:00
|
|
|
|
|
|
|
desc := descriptor
|
|
|
|
desc.SigHashes = hc
|
|
|
|
desc.InputIndex = inputIndex
|
|
|
|
|
|
|
|
switch wt {
|
|
|
|
case CommitmentTimeLock:
|
2018-11-18 07:48:41 +03:00
|
|
|
witness, err := CommitSpendTimeout(signer, desc, tx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-01-16 17:47:43 +03:00
|
|
|
return &Script{
|
2018-11-18 07:48:41 +03:00
|
|
|
Witness: witness,
|
|
|
|
}, nil
|
2018-01-17 04:59:43 +03:00
|
|
|
|
2020-03-06 18:11:46 +03:00
|
|
|
case CommitmentToRemoteConfirmed:
|
|
|
|
witness, err := CommitSpendToRemoteConfirmed(
|
|
|
|
signer, desc, tx,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Script{
|
|
|
|
Witness: witness,
|
|
|
|
}, nil
|
|
|
|
|
2020-03-10 15:23:17 +03:00
|
|
|
case CommitmentAnchor:
|
|
|
|
witness, err := CommitSpendAnchor(signer, desc, tx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Script{
|
|
|
|
Witness: witness,
|
|
|
|
}, nil
|
|
|
|
|
2017-05-07 14:04:28 +03:00
|
|
|
case CommitmentNoDelay:
|
2019-08-01 06:02:52 +03:00
|
|
|
witness, err := CommitSpendNoDelay(signer, desc, tx, false)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Script{
|
|
|
|
Witness: witness,
|
|
|
|
}, nil
|
|
|
|
|
|
|
|
case CommitSpendNoDelayTweakless:
|
|
|
|
witness, err := CommitSpendNoDelay(signer, desc, tx, true)
|
2018-11-18 07:48:41 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-01-16 17:47:43 +03:00
|
|
|
return &Script{
|
2018-11-18 07:48:41 +03:00
|
|
|
Witness: witness,
|
|
|
|
}, nil
|
2018-01-17 04:59:43 +03:00
|
|
|
|
2017-05-07 14:04:28 +03:00
|
|
|
case CommitmentRevoke:
|
2018-11-18 07:48:41 +03:00
|
|
|
witness, err := CommitSpendRevoke(signer, desc, tx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-01-16 17:47:43 +03:00
|
|
|
return &Script{
|
2018-11-18 07:48:41 +03:00
|
|
|
Witness: witness,
|
|
|
|
}, nil
|
2018-01-17 04:59:43 +03:00
|
|
|
|
2017-09-06 23:39:45 +03:00
|
|
|
case HtlcOfferedRevoke:
|
2018-11-18 07:48:41 +03:00
|
|
|
witness, err := ReceiverHtlcSpendRevoke(signer, desc, tx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-01-16 17:47:43 +03:00
|
|
|
return &Script{
|
2018-11-18 07:48:41 +03:00
|
|
|
Witness: witness,
|
|
|
|
}, nil
|
2018-01-17 04:59:43 +03:00
|
|
|
|
2017-09-06 23:39:45 +03:00
|
|
|
case HtlcAcceptedRevoke:
|
2018-11-18 07:48:41 +03:00
|
|
|
witness, err := SenderHtlcSpendRevoke(signer, desc, tx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-01-16 17:47:43 +03:00
|
|
|
return &Script{
|
2018-11-18 07:48:41 +03:00
|
|
|
Witness: witness,
|
|
|
|
}, nil
|
2018-01-17 04:59:43 +03:00
|
|
|
|
|
|
|
case HtlcOfferedTimeoutSecondLevel:
|
2018-11-18 07:48:41 +03:00
|
|
|
witness, err := HtlcSecondLevelSpend(signer, desc, tx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-01-16 17:47:43 +03:00
|
|
|
return &Script{
|
2018-11-18 07:48:41 +03:00
|
|
|
Witness: witness,
|
|
|
|
}, nil
|
2018-01-17 04:59:43 +03:00
|
|
|
|
|
|
|
case HtlcAcceptedSuccessSecondLevel:
|
2018-11-18 07:48:41 +03:00
|
|
|
witness, err := HtlcSecondLevelSpend(signer, desc, tx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-01-16 17:47:43 +03:00
|
|
|
return &Script{
|
2018-11-18 07:48:41 +03:00
|
|
|
Witness: witness,
|
|
|
|
}, nil
|
2018-01-17 04:59:43 +03:00
|
|
|
|
|
|
|
case HtlcOfferedRemoteTimeout:
|
|
|
|
// We pass in a value of -1 for the timeout, as we
|
|
|
|
// expect the caller to have already set the lock time
|
|
|
|
// value.
|
2019-01-16 17:47:43 +03:00
|
|
|
witness, err := ReceiverHtlcSpendTimeout(signer, desc, tx, -1)
|
2018-11-18 07:48:41 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-01-16 17:47:43 +03:00
|
|
|
return &Script{
|
2018-11-18 07:48:41 +03:00
|
|
|
Witness: witness,
|
|
|
|
}, nil
|
2018-01-17 04:59:43 +03:00
|
|
|
|
2018-01-21 06:57:34 +03:00
|
|
|
case HtlcSecondLevelRevoke:
|
2019-01-16 17:47:43 +03:00
|
|
|
witness, err := HtlcSpendRevoke(signer, desc, tx)
|
2018-11-18 07:48:41 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-01-16 17:47:43 +03:00
|
|
|
return &Script{
|
2018-11-18 07:48:41 +03:00
|
|
|
Witness: witness,
|
|
|
|
}, nil
|
|
|
|
|
2018-11-18 07:51:58 +03:00
|
|
|
case WitnessKeyHash:
|
|
|
|
fallthrough
|
|
|
|
case NestedWitnessKeyHash:
|
|
|
|
return signer.ComputeInputScript(tx, desc)
|
2018-01-21 06:57:34 +03:00
|
|
|
|
2017-05-07 14:04:28 +03:00
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unknown witness type: %v", wt)
|
|
|
|
}
|
|
|
|
}
|
2019-10-07 14:41:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// SizeUpperBound returns the maximum length of the witness of this witness
|
|
|
|
// type if it would be included in a tx. We also return if the output itself is
|
|
|
|
// a nested p2sh output, if so then we need to take into account the extra
|
|
|
|
// sigScript data size.
|
|
|
|
//
|
|
|
|
// NOTE: This is part of the WitnessType interface.
|
|
|
|
func (wt StandardWitnessType) SizeUpperBound() (int, bool, error) {
|
|
|
|
switch wt {
|
|
|
|
|
|
|
|
// Outputs on a remote commitment transaction that pay directly to us.
|
|
|
|
case CommitSpendNoDelayTweakless:
|
|
|
|
fallthrough
|
|
|
|
case WitnessKeyHash:
|
|
|
|
fallthrough
|
|
|
|
case CommitmentNoDelay:
|
|
|
|
return P2WKHWitnessSize, false, nil
|
|
|
|
|
|
|
|
// Outputs on a past commitment transaction that pay directly
|
|
|
|
// to us.
|
|
|
|
case CommitmentTimeLock:
|
|
|
|
return ToLocalTimeoutWitnessSize, false, nil
|
|
|
|
|
2020-03-06 18:11:46 +03:00
|
|
|
// 1 CSV time locked output to us on remote commitment.
|
|
|
|
case CommitmentToRemoteConfirmed:
|
|
|
|
return ToRemoteConfirmedWitnessSize, false, nil
|
|
|
|
|
2020-03-10 15:23:17 +03:00
|
|
|
// Anchor output on the commitment transaction.
|
|
|
|
case CommitmentAnchor:
|
|
|
|
return AnchorWitnessSize, false, nil
|
|
|
|
|
2019-10-07 14:41:46 +03:00
|
|
|
// Outgoing second layer HTLC's that have confirmed within the
|
|
|
|
// chain, and the output they produced is now mature enough to
|
|
|
|
// sweep.
|
|
|
|
case HtlcOfferedTimeoutSecondLevel:
|
|
|
|
return ToLocalTimeoutWitnessSize, false, nil
|
|
|
|
|
|
|
|
// Incoming second layer HTLC's that have confirmed within the
|
|
|
|
// chain, and the output they produced is now mature enough to
|
|
|
|
// sweep.
|
|
|
|
case HtlcAcceptedSuccessSecondLevel:
|
|
|
|
return ToLocalTimeoutWitnessSize, false, nil
|
|
|
|
|
|
|
|
// An HTLC on the commitment transaction of the remote party,
|
|
|
|
// that has had its absolute timelock expire.
|
|
|
|
case HtlcOfferedRemoteTimeout:
|
|
|
|
return AcceptedHtlcTimeoutWitnessSize, false, nil
|
|
|
|
|
|
|
|
// An HTLC on the commitment transaction of the remote party,
|
|
|
|
// that can be swept with the preimage.
|
|
|
|
case HtlcAcceptedRemoteSuccess:
|
|
|
|
return OfferedHtlcSuccessWitnessSize, false, nil
|
|
|
|
|
|
|
|
// A nested P2SH input that has a p2wkh witness script. We'll mark this
|
|
|
|
// as nested P2SH so the caller can estimate the weight properly
|
|
|
|
// including the sigScript.
|
|
|
|
case NestedWitnessKeyHash:
|
|
|
|
return P2WKHWitnessSize, true, nil
|
|
|
|
|
|
|
|
// The revocation output on a revoked commitment transaction.
|
|
|
|
case CommitmentRevoke:
|
|
|
|
return ToLocalPenaltyWitnessSize, false, nil
|
|
|
|
|
|
|
|
// The revocation output on a revoked HTLC that we offered to the remote
|
|
|
|
// party.
|
|
|
|
case HtlcOfferedRevoke:
|
|
|
|
return OfferedHtlcPenaltyWitnessSize, false, nil
|
|
|
|
|
|
|
|
// The revocation output on a revoked HTLC that was sent to us.
|
|
|
|
case HtlcAcceptedRevoke:
|
|
|
|
return AcceptedHtlcPenaltyWitnessSize, false, nil
|
|
|
|
|
|
|
|
// The revocation output of a second level output of an HTLC.
|
|
|
|
case HtlcSecondLevelRevoke:
|
|
|
|
return ToLocalPenaltyWitnessSize, false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0, false, fmt.Errorf("unexpected witness type: %v", wt)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddWeightEstimation adds the estimated size of the witness in bytes to the
|
2019-10-23 14:00:25 +03:00
|
|
|
// given weight estimator.
|
2019-10-07 14:41:46 +03:00
|
|
|
//
|
|
|
|
// NOTE: This is part of the WitnessType interface.
|
2019-10-23 14:00:25 +03:00
|
|
|
func (wt StandardWitnessType) AddWeightEstimation(e *TxWeightEstimator) error {
|
2019-10-07 14:41:46 +03:00
|
|
|
// For fee estimation purposes, we'll now attempt to obtain an
|
|
|
|
// upper bound on the weight this input will add when fully
|
|
|
|
// populated.
|
|
|
|
size, isNestedP2SH, err := wt.SizeUpperBound()
|
|
|
|
if err != nil {
|
2019-10-23 14:00:25 +03:00
|
|
|
return err
|
2019-10-07 14:41:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// If this is a nested P2SH input, then we'll need to factor in
|
|
|
|
// the additional data push within the sigScript.
|
|
|
|
if isNestedP2SH {
|
2019-10-23 14:00:25 +03:00
|
|
|
e.AddNestedP2WSHInput(size)
|
2019-10-07 14:41:46 +03:00
|
|
|
} else {
|
2019-10-23 14:00:25 +03:00
|
|
|
e.AddWitnessInput(size)
|
2019-10-07 14:41:46 +03:00
|
|
|
}
|
2017-05-07 14:04:28 +03:00
|
|
|
|
2019-10-23 14:00:25 +03:00
|
|
|
return nil
|
2017-05-07 14:04:28 +03:00
|
|
|
}
|