public async Task <T> CreateTokenAsync <T>(T token, NexusUser user, CancellationToken cToken = default) where T : Token { cToken.ThrowIfCancellationRequested(); user.Validate(); token.Validate(); var param = new Dictionary <string, string> { { "pin", user.Pin.ToString() }, { "session", user.GenesisId.Session }, { "identifier", token.Identifier }, { "name", token.Name }, { "type", token.Type } }; if (token is TokenRegister register) { param.Add("supply", register.Supply.ToString(CultureInfo.InvariantCulture)); } var response = await PostAsync <NexusCreationResponse>("tokens/create", new NexusRequest(param), cToken); if (string.IsNullOrWhiteSpace(response?.Address)) { throw new InvalidOperationException($"{token.Name} creation failed"); } token.Address = response.Address; token.Tx = response.TxId; return(token); }
public async Task <Asset> CreateAssetAsync(Asset asset, NexusUser user, CancellationToken token = default) { token.ThrowIfCancellationRequested(); user.Validate(); asset.Validate(); var request = new NexusRequest(new Dictionary <string, string> { { "pin", user.Pin.ToString() }, { "session", user.GenesisId.Session }, { "data", asset.Data }, { "name", asset.Name } }); var response = await PostAsync <NexusCreationResponse>("assets/create", request, token); if (string.IsNullOrWhiteSpace(response?.Address)) { throw new InvalidOperationException($"{asset.Name} creation failed"); } asset.Address = response.Address; asset.TxId = response.TxId; asset.Genesis = user.GenesisId.Genesis; asset.CreatedOn = DateTime.Now; return(asset); }
public async Task <object> TokeniseAsset(Asset asset, Token nexusToken, NexusUser user, CancellationToken token = default) { token.ThrowIfCancellationRequested(); user.Validate(); asset.Validate(); nexusToken.Validate(); var(aKey, aVal) = asset.GetKeyVal("asset_address", "asset_name"); var(tKey, tVal) = nexusToken.GetKeyVal("token_address", "token_name"); var request = new NexusRequest(new Dictionary <string, string> { { "pin", user.Pin.ToString() }, { "session", user.GenesisId.Session }, { aKey, aVal }, { tKey, tVal } }); return(await PostAsync <Asset>("assets/tokenize", request, token)); }