コード例 #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));
        }
コード例 #2
0
ファイル: SearchController.cs プロジェクト: mmcc1/DigitalMint
        public async Task <IActionResult> SearchCoin(Search search)
        {
            string sig = search.Signature;

            search.Signature = null;

            if (!CoinTools.ECVerify(JsonConvert.SerializeObject(search), sig, search.PublicKey))
            {
                return(NotFound());
            }

            MintDBContext db = new MintDBContext();

            List <Guid> mc = await db.MintHolders.Where(x => x.PublicKey == search.PublicKey).Select(x => x.MintCoinId).ToListAsync();

            List <MintCoin> mccoins = new List <MintCoin>();
            List <Coin>     coins   = new List <Coin>();

            for (int i = 0; i < mc.Count; i++)
            {
                mccoins.Add(await db.MintCoins.Where(x => x.Id == mc[i]).Include(x => x.Holders).SingleAsync());
            }

            for (int i = 0; i < mccoins.Count; i++)
            {
                Coin coin = new Coin();
                coin.CountryCode      = mccoins[i].CountryCode;
                coin.CurrencyCode     = mccoins[i].CurrencyCode;
                coin.PurposeCode      = mccoins[i].PurposeCode;
                coin.HolderHash       = mccoins[i].HolderHash;
                coin.Holders          = new List <Holder>();
                coin.IssueDate        = mccoins[i].IssueDate;
                coin.IssuingAuthority = mccoins[i].IssuingAuthority;
                coin.IssuingHash      = mccoins[i].IssuingHash;
                coin.SerialNumber     = mccoins[i].SerialNumber;
                coin.Value            = mccoins[i].Value;

                for (int j = 0; j < mccoins[i].Holders.Count; j++)
                {
                    Holder holder = new Holder();
                    holder.PublicKey = mccoins[i].Holders[j].PublicKey;

                    coin.Holders.Add(holder);
                }

                coins.Add(coin);
            }

            return(Ok(coins));
        }
コード例 #3
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));
        }