code: func signMultiSig(tx *wire.MsgTx, idx int, subScript []byte, hashType SigHashType,
  	addresses []btcutil.Address, nRequired int, kdb KeyDB) ([]byte, bool) {
  	// We start with a single OP_FALSE to work around the (now standard)
  	// but in the reference implementation that causes a spurious pop at
  	// the end of OP_CHECKMULTISIG.
  	builder := NewScriptBuilder().AddOp(OP_FALSE)
  	signed := 0
  	for _, addr := range addresses {
  		key, _, err := kdb.GetKey(addr)
  		if err != nil {
  			continue
  		}
  		sig, err := RawTxInSignature(tx, idx, subScript, hashType, key)
  		if err != nil {
  			continue
  		}
  
  		builder.AddData(sig)
  		signed++
  		if signed == nRequired {
  			break
  		}
  
  	}
  
  	script, _ := builder.Script()
  	return script, signed == nRequired
  }
docs: // signMultiSig signs as many of the outputs in the provided multisig script as
  // possible. It returns the generated script and a boolean if the script fulfils
  // the contract (i.e. nrequired signatures are provided).  Since it is arguably
  // legal to not be able to sign any of the outputs, no error is returned.