dcrd/txscript/stdscript/address.go
Dave Collins 7d97fd5ff8
stdscript: Move from internal/staging to txscript.
This moves the new stdscript package from the internal staging area to
the txscript module and updates the relevant paths and package README.md
accordingly.
2021-11-18 12:29:53 -06:00

30 lines
1.2 KiB
Go

// Copyright (c) 2021 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
// Package stdscript provides facilities for working with standard scripts.
package stdscript
import "github.com/decred/dcrd/txscript/v4/stdaddr"
// ExtractAddrs analyzes the passed public key script and returns the associated
// script type along with any addresses associated with it when possible.
//
// This function only works for standard script types and any data that fails to
// produce a valid address is omitted from the results. This means callers must
// not blindly assume the slice will be of a particular length for a given
// returned script type and should always check the length prior to access in
// case the addresses were not able to be created.
//
// NOTE: Version 0 scripts are the only currently supported version. It will
// always return a nonstandard script type and no addresses for other script
// versions.
func ExtractAddrs(scriptVersion uint16, pkScript []byte, params stdaddr.AddressParamsV0) (ScriptType, []stdaddr.Address) {
switch scriptVersion {
case 0:
return ExtractAddrsV0(pkScript, params)
}
return STNonStandard, nil
}