/// <summary> /// Creates a new Link from the given builder, signs it and executes the GraphQL /// mutation. /// </summary> /// <typeparam name="TLinkData"></typeparam> /// <param name="linkBuilder">The linkBuilder<see cref="TraceLinkBuilder{TLinkData}"/></param> /// <param name="firstTry">if this is not the first try, do not retry</param> /// <returns>The <see cref="Task{TraceState{TState, TLinkData}}"/></returns> private async Task <TraceState <TState, TLinkData> > CreateLinkAsync <TLinkData>(TraceLinkBuilder <TLinkData> linkBuilder, bool firstTry = true) { // extract signing key from config SdkConfig sdkConfig = await GetConfigAsync(); Ed25519PrivateKeyParameters signingPrivateKey = sdkConfig.SigningPrivateKey; // build the link TraceLink <TLinkData> link = linkBuilder.Build(); // sign the link link.Sign(signingPrivateKey.GetEncoded(), "[version,data,meta]"); string linkObjJson = JsonHelper.ToJson(link.ALink); Dictionary <string, object> linkObj = JsonHelper.ObjectToMap(link.GetLink()); Dictionary <string, object> dataObj = JsonHelper.ObjectToMap(((TraceLink <TLinkData>)link).FormData()); Dictionary <string, object> variables = new Dictionary <string, object> { ["link"] = linkObj, ["data"] = dataObj }; try { // execute graphql query GraphQLResponse <dynamic> jsonResponse = await this.client.GraphqlAsync(GraphQL.MUTATION_CREATELINK, variables, null, null); var trace = jsonResponse.Data.createLink.trace; return(this.MakeTraceState <TLinkData>(trace)); } catch (TraceSdkException e) { if (firstTry && e.Message == ERROR_CONFIG_DEPRECATED) { var cfg = await this.GetConfigAsync(true); linkBuilder.WithConfigId(cfg.ConfigId); link.GetLink().Signatures.Clear(); return(await this.CreateLinkAsync(linkBuilder, false)); } throw e; } }
/// <summary> /// Creates a new Link from the given builder, signs it and executes the GraphQL /// mutation. /// </summary> /// <typeparam name="TLinkData"></typeparam> /// <param name="linkBuilder">The linkBuilder<see cref="TraceLinkBuilder{TLinkData}"/></param> /// <returns>The <see cref="Task{TraceState{TState, TLinkData}}"/></returns> private async Task <TraceState <TState, TLinkData> > CreateLinkAsync <TLinkData>(TraceLinkBuilder <TLinkData> linkBuilder) { // extract signing key from config SdkConfig sdkConfig = await GetConfigAsync(); Ed25519PrivateKeyParameters signingPrivateKey = sdkConfig.SigningPrivateKey; // build the link TraceLink <TLinkData> link = linkBuilder.Build(); // sign the link link.Sign(signingPrivateKey.GetEncoded(), "[version,data,meta]"); string linkObjJson = JsonHelper.ToJson(link.ALink); Dictionary <string, object> linkObj = JsonHelper.ObjectToMap(link.GetLink()); Dictionary <string, object> dataObj = JsonHelper.ObjectToMap(((TraceLink <TLinkData>)link).FormData()); Dictionary <string, object> variables = new Dictionary <string, object> { ["link"] = linkObj, ["data"] = dataObj }; // Debug.WriteLine("Request : " + JsonHelper.ToJson(dataObj)); // execute graphql query GraphQLResponse jsonResponse = await this.client.GraphqlAsync(GraphQL.MUTATION_CREATELINK, variables, null, null); var trace = jsonResponse.Data.createLink.trace; return(this.MakeTraceState <TLinkData>(trace)); }