public Script GenerateScriptPubKey(FederationId federationId) { var ops = new List <Op>(); ops.Add(Op.GetPushOp(federationId.ToBytes())); ops.Add(OpcodeType.OP_FEDERATION); ops.Add(OpcodeType.OP_CHECKMULTISIG); return(new Script(ops)); }
/// <summary> /// Creates a new federation from a set of transaction signing keys. /// </summary> /// <param name="transactionSigningPubKeys">A list of transaction signing PubKeys.</param> /// <param name="signaturesRequired">The amount of signatures required to ensure that the transaction is fully signed.</param> public Federation(IEnumerable<PubKey> transactionSigningPubKeys, int? signaturesRequired = null) { // Ensures that the federation id will always map to the same members in the same order. this.transactionSigningKeys = transactionSigningPubKeys.OrderBy(k => k.ToHex()).ToArray(); this.signaturesRequired = signaturesRequired ?? (this.transactionSigningKeys.Length + 1) / 2; // The federationId is derived by XOR'ing all the genesis federation members. byte[] federationId = this.transactionSigningKeys.First().ToBytes(); foreach (PubKey pubKey in this.transactionSigningKeys.Skip(1)) { byte[] pubKeyBytes = pubKey.ToBytes(); for (int i = 0; i < federationId.Length; i++) federationId[i] ^= pubKeyBytes[i]; } this.Id = new FederationId(federationId); this.MultisigScript = PayToFederationTemplate.Instance.GenerateScriptPubKey(this.Id); }
public IFederation GetFederation(FederationId federationId) { return(this.federations.TryGetValue(federationId, out IFederation federation) ? federation : null); }