public async Task AddAsset(InboundTransaction transaction)
        {
            byte[] serializedMutation = await CreateTransaction(transaction);

            if (serializedMutation == null)
            {
                return;
            }

            await SignAndSubmit(serializedMutation);
        }
        private async Task <byte[]> CreateTransaction(InboundTransaction transaction)
        {
            List <Record> records = new List <Record>();

            string issuanceAccount = $"/asset/{assetName}/in/{transaction.TransactionHash}/{transaction.OutputIndex}/";
            string asset           = $"/asset/{assetName}/";
            string toAddress       = transaction.Address;

            HttpClient          client           = new HttpClient();
            ByteString          issuanceKey      = Encode($"{issuanceAccount}:ACC:{asset}");
            HttpResponseMessage getValueResponse = await client.GetAsync(new Uri(tedChainUri, $"record?key={issuanceKey.ToString()}"));

            string stringResponse = await getValueResponse.EnsureSuccessStatusCode().Content.ReadAsStringAsync();

            ByteString issuanceVersion = ByteString.Parse((string)JObject.Parse(stringResponse)["version"]);

            // The transaction has already been submitted
            if (issuanceVersion.Value.Count != 0)
            {
                return(null);
            }

            ByteString key = Encode($"{toAddress}:ACC:{asset}");

            getValueResponse = await client.GetAsync(new Uri(tedChainUri, $"record?key={key.ToString()}"));

            JObject    toAccount        = JObject.Parse(await getValueResponse.EnsureSuccessStatusCode().Content.ReadAsStringAsync());
            ByteString version          = ByteString.Parse((string)toAccount["version"]);
            long       currentToBalance = ParseInt(ByteString.Parse((string)toAccount["value"]));

            records.Add(new Record(
                            key: issuanceKey,
                            value: new ByteString(BitConverter.GetBytes(-transaction.Amount).Reverse().ToArray()),
                            version: ByteString.Empty));

            records.Add(new Record(
                            key: key,
                            value: new ByteString(BitConverter.GetBytes(currentToBalance + transaction.Amount).Reverse().ToArray()),
                            version: version));

            Mutation mutation = new Mutation(
                Encode(this.tedChainUri.ToString()),
                records,
                ByteString.Empty);

            return(MessageSerializer.SerializeMutation(mutation));
        }
        public async Task <string> MoveToStorage(InboundTransaction transaction)
        {
            NBitcoin.Transaction tx = new TransactionBuilder()
                                      .AddKeys(ReceivingKey)
                                      .AddCoins(new Coin(
                                                    uint256.Parse(transaction.TransactionHash),
                                                    (uint)transaction.OutputIndex,
                                                    transaction.Amount,
                                                    ReceivingKey.ScriptPubKey))
                                      .Send(storageKey.ScriptPubKey, transaction.Amount - defaultFees)
                                      .SendFees(defaultFees)
                                      .BuildTransaction(true);

            string result = await SubmitTransaction(new ByteString(tx.ToBytes()));

            return(result);
        }