package filter // BuildFromScripts builds a basic compact block filter from script elements and // returns its BIP158 serialization. // // It removes empty scripts and exact duplicate scripts before building, which // matches the BIP158 rule that nil elements are excluded and the basic filter // element set is a set. It does not attempt to identify OP_RETURN scripts or to // parse transactions: the caller must supply the basic filter element set, // namely the previous output scripts spent by non-coinbase inputs plus the // scriptPubKeys of all outputs except OP_RETURN outputs. // // The block hash is used in internal (little-endian) order, as for Build. func BuildFromScripts(scripts [][]byte, blockHash [32]byte) []byte { items := make([][]byte, 0, len(scripts)) seen := make(map[string]struct{}, len(scripts)) for _, script := range scripts { if len(script) == 0 { continue } if _, ok := seen[string(script)]; ok { continue } seen[string(script)] = struct{}{} items = append(items, script) } return Build(items, blockHash) }