public void TestIsValid() { Random random = new Random(); byte[] privateKey = new byte[32]; random.NextBytes(privateKey); KeyPair keyPair = new KeyPair(privateKey); ContractGroup contractGroup = new ContractGroup { PubKey = keyPair.PublicKey, Signature = new byte[20] }; Assert.AreEqual(false, contractGroup.IsValid(UInt160.Zero)); byte[] message = new byte[] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }; byte[] signature = Crypto.Default.Sign(message, keyPair.PrivateKey, keyPair.PublicKey.EncodePoint(false).Skip(1).ToArray()); contractGroup = new ContractGroup { PubKey = keyPair.PublicKey, Signature = signature }; Assert.AreEqual(true, contractGroup.IsValid(new UInt160(message))); }
public string WrapAll(string str, ContractGroup @group) { return(_template.Render( _contextMaker.Make(new { Namespace = _options.CsharpNamespaceOneFile, Contracts = str }) )); }
protected IEnumerable <ContractGroup> ChildGroups(ContractGroup group) { foreach (ContractGroup child in ContractGroup.AllGroups.Where(g => g != null && g.parent == group)) { yield return(child); foreach (ContractGroup descendent in ChildGroups(child)) { yield return(descendent); } } }
public static void ContractSpec(string symbol) { var contractLibraryApi = new ContractLibraryApi(); Contract contract = contractLibraryApi.FindContract(symbol); Log.Write(contract); ContractMaturity contractMaturity = contractLibraryApi.GetContractMaturity(contract.ContractMaturityId); Log.Write(contractMaturity); Product product = contractLibraryApi.GetProduct(contractMaturity.ProductId); Log.Write(product); Exchange exchange = contractLibraryApi.GetExchange(product.ExchangeId); Log.Write(exchange); ContractGroup contractGroup = contractLibraryApi.GetContractGroup(product.ContractGroupId); Log.Write(contractGroup); Currency currency = contractLibraryApi.GetCurrency(product.CurrencyId); Log.Write(currency); CurrencyRate currencyRate = contractLibraryApi.GetCurrencyRate(product.CurrencyId); Log.Write(currencyRate); ProductSession productSession = contractLibraryApi.GetProductSession(product.Id); Log.Write(productSession); ProductFeeParamsResponse productFees = contractLibraryApi.GetProductFeeParams(new GetProductFeeParams(new List <int?> { product.Id })); foreach (var fee in productFees._Params) { Log.Write(fee); } var riskApi = new RisksApi(); ProductMargin productMargin = riskApi.GetProductMargin(product.Id); Log.Write(productMargin); try { ContractMargin contractMargin = riskApi.GetContractMargin(contract.Id); Log.Write(contractMargin); } catch { Log.Write("Per-contract margin is not specified"); } }
private string ContractTypeDisplay(string contractTypeName) { if (!displayNameCache.ContainsKey(contractTypeName)) { string displayName = ContractGroup.GroupDisplayName(contractTypeName);; if (string.IsNullOrEmpty(displayName)) { displayName = contractTypeName.Replace("Contract", ""); } displayNameCache[contractTypeName] = displayName; } return(displayNameCache[contractTypeName]); }
public void TestClone() { Random random = new Random(); byte[] privateKey = new byte[32]; random.NextBytes(privateKey); KeyPair keyPair = new KeyPair(privateKey); ContractGroup contractGroup = new ContractGroup { PubKey = keyPair.PublicKey, Signature = new byte[20] }; var clone = contractGroup.Clone(); Assert.AreEqual(clone.ToJson().ToString(), contractGroup.ToJson().ToString()); }
public void TestClone() { Random random = new Random(); byte[] privateKey = new byte[32]; random.NextBytes(privateKey); KeyPair keyPair = new KeyPair(privateKey); ContractGroup contractGroup = new ContractGroup { PubKey = keyPair.PublicKey, Signature = new byte[20] }; var clone = new ContractGroup(); ((IInteroperable)clone).FromStackItem(contractGroup.ToStackItem(null)); Assert.AreEqual(clone.ToJson().ToString(), contractGroup.ToJson().ToString()); }
public string WrapAll(string str, ContractGroup group) { // calculate all base classes and write union types to end of namespace var bases = string.Join( Environment.NewLine + Environment.NewLine, group.Groups.Values.ToArray() .SelectMany(_ => _) .Where(_ => (_ is ContractDesc cd) && cd.Base != null && !string.IsNullOrWhiteSpace(cd.Base.Name)) .GroupBy(_ => (_ as ContractDesc).Base.Name) .Select(_ => $@"export type I{_options.ContractNameTempate(new ContractDesc {Name = _.Key})} = {string.Join(Environment.NewLine, _.ToArray().Select(nestType => Utils.Ident($"| I{_options.ContractNameTempate(nestType)}", _options.IdentSize)))}")); return($@" {NamespaceOrModule} {{ {Utils.Ident(str, _options.IdentSize)} {Utils.Ident(bases, _options.IdentSize)} }} "); }
private void EmitOneFile([NotNull] string output, [NotNull] ContractGroup parsed) { var buffer = new List <string>(); foreach (var group in parsed.Groups) { foreach (var contract in group.Value) { var contractStr = ""; // render contract string if (contract is ContractDesc cd) { contractStr = _options.ContractStringify.Stringify(cd); } if (contract is ContractEnumDesc ed) { contractStr = _options.ContractEnumStringify.Stringify(ed); } if (contract is GenericDesc gd) { contractStr = _options.ContractGenericStringify.Stringify(gd); } if (!string.IsNullOrWhiteSpace(contractStr)) { buffer.Add(_options.ManyContractsWrapper.WrapOne(contractStr)); } } } var result = string.Join(Environment.NewLine + Environment.NewLine, buffer); var wrappedStr = _options.ManyContractsWrapper.WrapAll(result, parsed); var filename = _options.Filename; if (filename == null) { throw new Exception("filename must be defined"); } var filepath = Path.Combine(output, filename); WriteToFile(filepath, wrappedStr); }
private void EmitFilePerContract([NotNull] string output, [NotNull] ContractGroup parsed) { if (_options.FileTemplate == null) { throw new Exception("FileTemplate option must be defined"); } foreach (var group in parsed.Groups) { foreach (var contract in group.Value) { var contractStr = ""; // render contract string if (contract is ContractDesc cd) { contractStr = _options.ContractStringify.Stringify(cd); } if (contract is ContractEnumDesc ed) { contractStr = _options.ContractEnumStringify.Stringify(ed); } if (contract is GenericDesc gd) { contractStr = _options.ContractGenericStringify.Stringify(gd); } if (!string.IsNullOrWhiteSpace(contractStr)) { var wrappedStr = _options.PerFileContractWrapper.Wrap(contractStr, group.Key, contract); var filename = _options.FileTemplate(group.Key, contract); if (filename == null) { throw new Exception("filename must be defined"); } var filepath = Path.Combine(output, filename); WriteToFile(filepath, wrappedStr); } } } }
protected override void OnLoadFromConfig(ConfigNode node) { base.OnLoadFromConfig(node); currencies = ConfigNodeUtil.ParseValue <List <Currency> >(node, "currency"); contractTypes = ConfigNodeUtil.ParseValue <List <string> >(node, "contractType"); effectDescription = ConfigNodeUtil.ParseValue <string>(node, "effectDescription"); affectReasons = ConfigNodeUtil.ParseValue <List <TransactionReasons> >(node, "AffectReason"); multipliers = ConfigNodeUtil.ParseValue <List <float> >(node, "multiplier"); trait = ConfigNodeUtil.ParseValue <string>(node, "trait", null); // Add any child groups foreach (string type in contractTypes.ToList()) { ContractGroup group = ContractGroup.AllGroups.Where(g => g != null && g.name == type).FirstOrDefault(); if (group != null) { foreach (ContractGroup child in ChildGroups(group)) { contractTypes.Add(child.name); } } } }
public static string OrderKey(Contract c) { ConfiguredContract cc = c as ConfiguredContract; if (cc != null) { string key = cc.contractType.group == null ? "aaa" : cc.contractType.group.sortKey; for (ContractGroup group = cc.contractType.group; group != null; group = group.parent) { if (group.parent != null) { key = group.parent.sortKey + "." + key; } } key += "." + cc.contractType.sortKey; return key; } else { return DisplayName(c.GetType()) + "." + c.Title; } }
public static string OrderKey(ContractGroup group) { return group == null ? "aaa" : group.sortKey; }
public GroupContainer(ContractGroup group) { this.group = group; // Set the agent from the group if (group != null && group.agent != null) { agent = group.agent; } // Fallback to trying to find the most appropriate agent else { ContractType contractType = ContractType.AllValidContractTypes.Where(ct => ct != null && ct.group == group).FirstOrDefault(); agent = contractType != null ? contractType.agent : null; // Final fallback is the Contract Configurator agency if (agent == null) { agent = GetAgent("Contract Configurator"); } } }