Exemplo n.º 1
0
        public async Task <IActionResult> IssueCoin(IssueCoinRequest issueCoinRequest)
        {
            IssueCoin     iC   = new IssueCoin();
            Coin          coin = iC.Create(issueCoinRequest.IssuingAuthority, issueCoinRequest.CountryCode, issueCoinRequest.CurrencyCode, issueCoinRequest.PurposeCode, issueCoinRequest.Value, privateECKey, issueCoinRequest.HolderPublicKeys);
            MintDBContext db   = new MintDBContext();

            MintCoin mc = new MintCoin()
            {
                CountryCode      = coin.CountryCode,
                CurrencyCode     = coin.CurrencyCode,
                PurposeCode      = coin.PurposeCode,
                HolderHash       = coin.HolderHash,
                Id               = Guid.NewGuid(),
                IssueDate        = DateTime.UtcNow,
                IssuingAuthority = coin.IssuingAuthority,
                IssuingHash      = coin.IssuingHash,
                SerialNumber     = coin.SerialNumber,
                Value            = coin.Value,
                Holders          = new List <MintHolder>()
            };

            for (int i = 0; i < coin.Holders.Count; i++)
            {
                mc.Holders.Add(new MintHolder()
                {
                    Id = Guid.NewGuid(), PublicKey = coin.Holders[i].PublicKey
                });
            }

            await db.MintCoins.AddAsync(mc);

            await db.SaveChangesAsync();

            return(Ok(coin));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> TransferCoin(Transfer transfer)
        {
            Coin          coin = new Coin();
            MintDBContext db   = new MintDBContext();

            MintCoin mc = db.MintCoins.Where(x => x.SerialNumber == transfer.SerialNumber).Include(x => x.Holders).Single();

            coin.CountryCode      = mc.CountryCode;
            coin.CurrencyCode     = mc.CurrencyCode;
            coin.PurposeCode      = mc.PurposeCode;
            coin.HolderHash       = mc.HolderHash;
            coin.IssueDate        = mc.IssueDate;
            coin.IssuingAuthority = mc.IssuingAuthority;
            coin.IssuingHash      = mc.IssuingHash;
            coin.SerialNumber     = mc.SerialNumber;
            coin.Value            = mc.Value;
            coin.Holders          = new List <Holder>();

            for (int i = 0; i < mc.Holders.Count; i++)
            {
                coin.Holders.Add(new Holder()
                {
                    PublicKey = mc.Holders[i].PublicKey
                });
            }

            TransferCoin tc = new TransferCoin();
            Coin         transferredCoin = tc.Create(transfer, coin, privateECKey);

            if (transferredCoin != null)
            {
                for (int i = 0; i < mc.Holders.Count; i++)
                {
                    db.MintHolders.Remove(mc.Holders[i]);
                    await db.SaveChangesAsync();
                }

                db.MintCoins.Remove(mc);
                await db.SaveChangesAsync();
            }

            MintCoin transferredMc = new MintCoin()
            {
                CountryCode      = transferredCoin.CountryCode,
                CurrencyCode     = transferredCoin.CurrencyCode,
                HolderHash       = transferredCoin.HolderHash,
                PurposeCode      = transferredCoin.PurposeCode,
                Id               = Guid.NewGuid(),
                IssueDate        = DateTime.UtcNow,
                IssuingAuthority = transferredCoin.IssuingAuthority,
                IssuingHash      = transferredCoin.IssuingHash,
                SerialNumber     = transferredCoin.SerialNumber,
                Value            = transferredCoin.Value,
                Holders          = new List <MintHolder>()
            };

            for (int i = 0; i < coin.Holders.Count; i++)
            {
                transferredMc.Holders.Add(new MintHolder()
                {
                    Id = Guid.NewGuid(), PublicKey = transferredCoin.Holders[i].PublicKey
                });
            }

            await db.MintCoins.AddAsync(transferredMc);

            await db.SaveChangesAsync();

            return(Ok(transferredCoin));
        }