public static ExpressChain CreateBlockchain(int count) { var wallets = new List <(DevWallet wallet, Neo.Wallets.WalletAccount account)>(count); ushort GetPortNumber(int index, ushort portNumber) => (ushort)((49000 + (index * 1000)) + portNumber); try { for (var i = 1; i <= count; i++) { var wallet = new DevWallet($"node{i}"); var account = wallet.CreateAccount(); account.IsDefault = true; wallets.Add((wallet, account)); } var keys = wallets.Select(t => t.account.GetKey().PublicKey).ToArray(); var contract = Neo.SmartContract.Contract.CreateMultiSigContract((keys.Length * 2 / 3) + 1, keys); foreach (var(wallet, account) in wallets) { var multiSigContractAccount = wallet.CreateAccount(contract, account.GetKey()); multiSigContractAccount.Label = "MultiSigContract"; } // 49152 is the first port in the "Dynamic and/or Private" range as specified by IANA // http://www.iana.org/assignments/port-numbers var nodes = new List <ExpressConsensusNode>(count); for (var i = 0; i < count; i++) { nodes.Add(new ExpressConsensusNode() { TcpPort = GetPortNumber(i, 333), WebSocketPort = GetPortNumber(i, 334), RpcPort = GetPortNumber(i, 332), Wallet = wallets[i].wallet.ToExpressWallet() }); } return(new ExpressChain() { Magic = ExpressChain.GenerateMagicValue(), ConsensusNodes = nodes, }); } finally { foreach (var(wallet, _) in wallets) { wallet.Dispose(); } } }
internal static ExpressChain CreateChain(int nodeCount) { if (nodeCount != 1 && nodeCount != 4 && nodeCount != 7) { throw new ArgumentException("invalid blockchain node count", nameof(nodeCount)); } var wallets = new List <(DevWallet wallet, Neo.Wallets.WalletAccount account)>(nodeCount); for (var i = 1; i <= nodeCount; i++) { var wallet = new DevWallet($"node{i}"); var account = wallet.CreateAccount(); account.IsDefault = true; wallets.Add((wallet, account)); } var keys = wallets.Select(t => t.account.GetKey().PublicKey).ToArray(); var contract = Neo.SmartContract.Contract.CreateMultiSigContract((keys.Length * 2 / 3) + 1, keys); foreach (var(wallet, account) in wallets) { var multiSigContractAccount = wallet.CreateAccount(contract, account.GetKey()); multiSigContractAccount.Label = "MultiSigContract"; } // 49152 is the first port in the "Dynamic and/or Private" range as specified by IANA // http://www.iana.org/assignments/port-numbers var nodes = new List <ExpressConsensusNode>(nodeCount); for (var i = 0; i < nodeCount; i++) { nodes.Add(new ExpressConsensusNode() { TcpPort = GetPortNumber(i, 3), WebSocketPort = GetPortNumber(i, 4), RpcPort = GetPortNumber(i, 2), Wallet = wallets[i].wallet.ToExpressWallet() }); } return(new ExpressChain() { Magic = ExpressChain.GenerateMagicValue(), ConsensusNodes = nodes, });