Skip to content

Commit be499e2

Browse files
committed
tapsend: remove now unused functions
We are now validating the input amount and types when creating the allocations and no longer need this function.
1 parent f0f951c commit be499e2

File tree

2 files changed

+0
-320
lines changed

2 files changed

+0
-320
lines changed

tapsend/send.go

-102
Original file line numberDiff line numberDiff line change
@@ -277,108 +277,6 @@ func DescribeAddrs(addrs []*address.Tap) (*FundingDescriptor, error) {
277277
return desc, nil
278278
}
279279

280-
// AssetFromTapCommitment uses a script key to extract an asset from a given
281-
// Taproot Asset commitment.
282-
func AssetFromTapCommitment(tapCommitment *commitment.TapCommitment,
283-
specifier asset.Specifier,
284-
inputScriptKey btcec.PublicKey) (*asset.Asset, error) {
285-
286-
// The top-level Taproot Asset tree must have a non-empty asset tree at
287-
// the leaf specified by the funding descriptor's asset (group) specific
288-
// commitment locator.
289-
tapKey := asset.TapCommitmentKey(specifier)
290-
assetCommitments := tapCommitment.Commitments()
291-
assetCommitment, ok := assetCommitments[tapKey]
292-
if !ok {
293-
return nil, fmt.Errorf("input commitment does "+
294-
"not contain asset=%s: %w", &specifier,
295-
ErrMissingInputAsset)
296-
}
297-
298-
// Determine whether issuance is disabled for the asset.
299-
issuanceDisabled := !specifier.HasGroupPubKey()
300-
301-
assetId, err := specifier.UnwrapIdOrErr()
302-
if err != nil {
303-
return nil, fmt.Errorf("asset from tap commitment: %w", err)
304-
}
305-
306-
// The asset tree must have a non-empty Asset at the location
307-
// specified by the sender's script key.
308-
assetCommitmentKey := asset.AssetCommitmentKey(
309-
assetId, &inputScriptKey, issuanceDisabled,
310-
)
311-
inputAsset, ok := assetCommitment.Asset(assetCommitmentKey)
312-
if !ok {
313-
return nil, fmt.Errorf("input commitment does not "+
314-
"contain leaf with script_key=%x: %w",
315-
inputScriptKey.SerializeCompressed(),
316-
ErrMissingInputAsset)
317-
}
318-
319-
return inputAsset, nil
320-
}
321-
322-
// ValidateInputs validates a set of inputs against a funding request. It
323-
// returns true if the inputs would be spent fully, otherwise false.
324-
func ValidateInputs(inputCommitments tappsbt.InputCommitments,
325-
expectedAssetType asset.Type, specifier asset.Specifier,
326-
outputAmount uint64) (bool, error) {
327-
328-
// Extract the input assets from the input commitments.
329-
inputAssets := make([]*asset.Asset, 0, len(inputCommitments))
330-
for prevID := range inputCommitments {
331-
tapCommitment := inputCommitments[prevID]
332-
senderScriptKey, err := prevID.ScriptKey.ToPubKey()
333-
if err != nil {
334-
return false, fmt.Errorf("unable to parse sender "+
335-
"script key: %v", err)
336-
}
337-
338-
// Gain the asset that we'll use as an input and in the process
339-
// validate the selected input and commitment.
340-
inputAsset, err := AssetFromTapCommitment(
341-
tapCommitment, specifier, *senderScriptKey,
342-
)
343-
if err != nil {
344-
return false, err
345-
}
346-
347-
// Ensure input asset has the expected type.
348-
if inputAsset.Type != expectedAssetType {
349-
return false, fmt.Errorf("unexpected input asset type")
350-
}
351-
352-
inputAssets = append(inputAssets, inputAsset)
353-
}
354-
355-
// Validate total amount of input assets and determine full value spend
356-
// status.
357-
var isFullValueSpend bool
358-
switch expectedAssetType {
359-
case asset.Normal:
360-
// Sum the total amount of the input assets.
361-
var totalInputsAmount uint64
362-
for _, inputAsset := range inputAssets {
363-
totalInputsAmount += inputAsset.Amount
364-
}
365-
366-
// Ensure that the input assets are sufficient to cover the amount
367-
// being sent.
368-
if totalInputsAmount < outputAmount {
369-
return false, ErrInsufficientInputAssets
370-
}
371-
372-
// Check if the input assets are fully spent.
373-
isFullValueSpend = totalInputsAmount == outputAmount
374-
375-
case asset.Collectible:
376-
isFullValueSpend = true
377-
}
378-
379-
return isFullValueSpend, nil
380-
}
381-
382280
// ValidateCommitmentKeysUnique makes sure the outputs of a set of virtual
383281
// packets don't lead to collisions in and of the trees (e.g. two asset outputs
384282
// with the same asset ID and script key in the same anchor output) or with

tapsend/send_test.go

-218
Original file line numberDiff line numberDiff line change
@@ -1873,224 +1873,6 @@ func TestProofVerifyFullValueSplit(t *testing.T) {
18731873
require.NoError(t, err)
18741874
}
18751875

1876-
// TestAddressValidInput tests edge cases around validating inputs for asset
1877-
// transfers with isValidInput.
1878-
func TestAddressValidInput(t *testing.T) {
1879-
t.Parallel()
1880-
1881-
for _, testCase := range addressValidInputTestCases {
1882-
success := t.Run(testCase.name, func(t *testing.T) {
1883-
inputAsset, checkedInputAsset, err := testCase.f(t)
1884-
require.ErrorIs(t, err, testCase.err)
1885-
if testCase.err == nil {
1886-
require.True(t, inputAsset.DeepEqual(
1887-
checkedInputAsset,
1888-
))
1889-
}
1890-
})
1891-
if !success {
1892-
return
1893-
}
1894-
}
1895-
}
1896-
1897-
func addrToFundDesc(addr address.Tap) *tapsend.FundingDescriptor {
1898-
assetSpecifier := asset.NewSpecifierOptionalGroupPubKey(
1899-
addr.AssetID, addr.GroupKey,
1900-
)
1901-
1902-
return &tapsend.FundingDescriptor{
1903-
AssetSpecifier: assetSpecifier,
1904-
Amount: addr.Amount,
1905-
}
1906-
}
1907-
1908-
type addressValidInputTestCase struct {
1909-
name string
1910-
f func(t *testing.T) (*asset.Asset, *asset.Asset, error)
1911-
err error
1912-
}
1913-
1914-
var addressValidInputTestCases = []addressValidInputTestCase{{
1915-
name: "valid normal",
1916-
f: func(t *testing.T) (*asset.Asset, *asset.Asset, error) {
1917-
state := initSpendScenario(t)
1918-
fundDesc := addrToFundDesc(state.address1)
1919-
1920-
inputAsset, err := tapsend.AssetFromTapCommitment(
1921-
&state.asset1TapTree, fundDesc.AssetSpecifier,
1922-
state.spenderScriptKey,
1923-
)
1924-
if err != nil {
1925-
return nil, nil, err
1926-
}
1927-
1928-
fullValue, err := tapsend.ValidateInputs(
1929-
tappsbt.InputCommitments{
1930-
state.asset1PrevID: &state.asset1TapTree,
1931-
}, inputAsset.Type, fundDesc.AssetSpecifier,
1932-
fundDesc.Amount,
1933-
)
1934-
if err != nil {
1935-
return nil, nil, err
1936-
}
1937-
require.True(t, fullValue)
1938-
1939-
return &state.asset1, inputAsset, nil
1940-
},
1941-
err: nil,
1942-
}, {
1943-
name: "valid collectible with group key",
1944-
f: func(t *testing.T) (*asset.Asset, *asset.Asset, error) {
1945-
state := initSpendScenario(t)
1946-
fundDesc := addrToFundDesc(state.address1CollectGroup)
1947-
1948-
inputAsset, err := tapsend.AssetFromTapCommitment(
1949-
&state.asset1CollectGroupTapTree,
1950-
fundDesc.AssetSpecifier, state.spenderScriptKey,
1951-
)
1952-
if err != nil {
1953-
return nil, nil, err
1954-
}
1955-
1956-
inputCommitment := &state.asset1CollectGroupTapTree
1957-
fullValue, err := tapsend.ValidateInputs(
1958-
tappsbt.InputCommitments{
1959-
state.asset1CollectGroupPrevID: inputCommitment,
1960-
}, inputAsset.Type, fundDesc.AssetSpecifier,
1961-
fundDesc.Amount,
1962-
)
1963-
if err != nil {
1964-
return nil, nil, err
1965-
}
1966-
require.True(t, fullValue)
1967-
1968-
return &state.asset1CollectGroup, inputAsset, nil
1969-
},
1970-
err: nil,
1971-
}, {
1972-
name: "valid asset split",
1973-
f: func(t *testing.T) (*asset.Asset, *asset.Asset, error) {
1974-
state := initSpendScenario(t)
1975-
fundDesc := addrToFundDesc(state.address1)
1976-
1977-
inputAsset, err := tapsend.AssetFromTapCommitment(
1978-
&state.asset2TapTree, fundDesc.AssetSpecifier,
1979-
state.spenderScriptKey,
1980-
)
1981-
if err != nil {
1982-
return nil, nil, err
1983-
}
1984-
1985-
fullValue, err := tapsend.ValidateInputs(
1986-
tappsbt.InputCommitments{
1987-
state.asset2PrevID: &state.asset2TapTree,
1988-
}, inputAsset.Type, fundDesc.AssetSpecifier,
1989-
fundDesc.Amount,
1990-
)
1991-
if err != nil {
1992-
return nil, nil, err
1993-
}
1994-
require.False(t, fullValue)
1995-
1996-
return &state.asset2, inputAsset, nil
1997-
},
1998-
err: nil,
1999-
}, {
2000-
name: "normal with insufficient amount",
2001-
f: func(t *testing.T) (*asset.Asset, *asset.Asset, error) {
2002-
state := initSpendScenario(t)
2003-
fundDesc := addrToFundDesc(state.address2)
2004-
2005-
inputAsset, err := tapsend.AssetFromTapCommitment(
2006-
&state.asset1TapTree, fundDesc.AssetSpecifier,
2007-
state.spenderScriptKey,
2008-
)
2009-
if err != nil {
2010-
return nil, nil, err
2011-
}
2012-
2013-
fullValue, err := tapsend.ValidateInputs(
2014-
tappsbt.InputCommitments{
2015-
state.asset1PrevID: &state.asset1TapTree,
2016-
}, inputAsset.Type, fundDesc.AssetSpecifier,
2017-
fundDesc.Amount,
2018-
)
2019-
if err != nil {
2020-
return nil, nil, err
2021-
}
2022-
require.True(t, fullValue)
2023-
2024-
return &state.asset1, inputAsset, nil
2025-
},
2026-
err: tapsend.ErrInsufficientInputAssets,
2027-
}, {
2028-
name: "collectible with missing input asset",
2029-
f: func(t *testing.T) (*asset.Asset, *asset.Asset, error) {
2030-
state := initSpendScenario(t)
2031-
fundDesc := addrToFundDesc(state.address1CollectGroup)
2032-
2033-
inputAsset, err := tapsend.AssetFromTapCommitment(
2034-
&state.asset1TapTree, fundDesc.AssetSpecifier,
2035-
state.spenderScriptKey,
2036-
)
2037-
if err != nil {
2038-
return nil, nil, err
2039-
}
2040-
2041-
fullValue, err := tapsend.ValidateInputs(
2042-
tappsbt.InputCommitments{
2043-
state.asset1PrevID: &state.asset1TapTree,
2044-
}, inputAsset.Type, fundDesc.AssetSpecifier,
2045-
fundDesc.Amount,
2046-
)
2047-
if err != nil {
2048-
return nil, nil, err
2049-
}
2050-
require.False(t, fullValue)
2051-
2052-
return &state.asset1, inputAsset, nil
2053-
},
2054-
err: tapsend.ErrMissingInputAsset,
2055-
}, {
2056-
name: "normal with bad sender script key",
2057-
f: func(t *testing.T) (*asset.Asset, *asset.Asset, error) {
2058-
state := initSpendScenario(t)
2059-
2060-
address1testnet, err := address.New(
2061-
address.V0, state.genesis1, nil, nil,
2062-
state.receiverPubKey, state.receiverPubKey,
2063-
state.normalAmt1, nil, &address.TestNet3Tap,
2064-
address.RandProofCourierAddr(t),
2065-
)
2066-
require.NoError(t, err)
2067-
2068-
fundDesc := addrToFundDesc(*address1testnet)
2069-
2070-
inputAsset, err := tapsend.AssetFromTapCommitment(
2071-
&state.asset1TapTree, fundDesc.AssetSpecifier,
2072-
state.receiverPubKey,
2073-
)
2074-
if err != nil {
2075-
return nil, nil, err
2076-
}
2077-
2078-
fullValue, err := tapsend.ValidateInputs(
2079-
tappsbt.InputCommitments{
2080-
state.asset1PrevID: &state.asset1TapTree,
2081-
}, inputAsset.Type, fundDesc.AssetSpecifier,
2082-
fundDesc.Amount,
2083-
)
2084-
if err != nil {
2085-
return nil, nil, err
2086-
}
2087-
require.True(t, fullValue)
2088-
2089-
return &state.asset1, inputAsset, nil
2090-
},
2091-
err: tapsend.ErrMissingInputAsset,
2092-
}}
2093-
20941876
// TestPayToAddrScript tests edge cases around creating a P2TR script with
20951877
// PayToAddrScript.
20961878
func TestPayToAddrScript(t *testing.T) {

0 commit comments

Comments
 (0)