github.com/MetalBlockchain/metalgo@v1.11.9/wallet/subnet/primary/common/spend.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package common 5 6 import ( 7 "github.com/MetalBlockchain/metalgo/ids" 8 "github.com/MetalBlockchain/metalgo/utils/set" 9 "github.com/MetalBlockchain/metalgo/vms/secp256k1fx" 10 ) 11 12 // MatchOwners attempts to match a list of addresses up to the provided 13 // threshold. 14 func MatchOwners( 15 owners *secp256k1fx.OutputOwners, 16 addrs set.Set[ids.ShortID], 17 minIssuanceTime uint64, 18 ) ([]uint32, bool) { 19 if owners.Locktime > minIssuanceTime { 20 return nil, false 21 } 22 23 sigs := make([]uint32, 0, owners.Threshold) 24 for i := uint32(0); i < uint32(len(owners.Addrs)) && uint32(len(sigs)) < owners.Threshold; i++ { 25 addr := owners.Addrs[i] 26 if addrs.Contains(addr) { 27 sigs = append(sigs, i) 28 } 29 } 30 return sigs, uint32(len(sigs)) == owners.Threshold 31 }