public bool ApplyContract(DbSnapshot dbSnapshot, Transfer transfer, long height) { if (transfer.type != "contract") { return(true); } if (transfer.addressIn == transfer.addressOut) { return(true); } if (transfer.data == null || transfer.data == "") { return(true); } //if (!transfer.CheckSign()) // return true; luaVMEnv.Execute(dbSnapshot, transfer, height); // 设置交易index Account accountIn = dbSnapshot.Accounts.Get(transfer.addressIn); if (accountIn == null) { accountIn = new Account() { address = transfer.addressIn, amount = "0", index = 0, nonce = 0 } } ; if (accountIn.nonce + 1 != transfer.nonce) { return(true); } accountIn.index += 1; accountIn.nonce += 1; dbSnapshot.Accounts.Add(accountIn.address, accountIn); if (transferShow) { dbSnapshot.BindTransfer2Account(transfer.addressIn, accountIn.index, transfer.hash); transfer.height = height; dbSnapshot.Transfers.Add(transfer.hash, transfer); } return(true); }
// 奖励上一周期的rule、本周期的MC出块rule , 出块的rule会得到两次奖励 public void ApplyReward(DbSnapshot dbSnapshot, Block mcblk) { var rewardKey = $"{mcblk.height}_Reward"; if (dbSnapshot.Get(rewardKey) == "1") { return; } dbSnapshot.Add(rewardKey, "1"); var amount = GetReward(mcblk.height).ToString(); var amountRule = GetRewardRule(mcblk.height).ToString(); Transfer Reward_Rule = null; Transfer Reward = null; if (transferShow) { Reward_Rule = new Transfer() { hash = "", type = "Reward_Rule", nonce = mcblk.height, amount = amountRule }; Reward_Rule.hash = Reward_Rule.ToHash(); Reward_Rule.height = mcblk.height; dbSnapshot.Transfers.Add(Reward_Rule.hash, Reward_Rule); Reward = new Transfer() { hash = "", type = "Reward_Mc", nonce = mcblk.height, data = mcblk.height.ToString(), amount = amount }; Reward.height = mcblk.height; dbSnapshot.Transfers.Add(Reward.hash = Reward.ToHash(), Reward); } // rule奖励 int ruleCount = 0; for (int ii = 0; ii < mcblk.linksblk.Count; ii++) { Block linkblk = blockMgr.GetBlock(mcblk.linksblk[ii]); if (linkblk != null && IsRule(mcblk.height, linkblk.Address)) { ruleCount++; Account linkAccount = dbSnapshot.Accounts.Get(linkblk.Address); if (linkAccount == null) { linkAccount = new Account() { address = linkblk.Address, amount = "0", index = 0, nonce = 0 } } ; linkAccount.amount = BigInt.Add(linkAccount.amount, amountRule); linkAccount.index += 1; dbSnapshot.Accounts.Add(linkAccount.address, linkAccount); if (transferShow) { dbSnapshot.BindTransfer2Account(linkAccount.address, linkAccount.index, Reward_Rule.hash); } } } // 出块奖励 Account account = dbSnapshot.Accounts.Get(mcblk.Address); if (account == null) { account = new Account() { address = mcblk.Address, amount = "0", index = 0, nonce = 0 } } ; account.amount = BigInt.Add(account.amount, amount); account.index += 1; dbSnapshot.Accounts.Add(account.address, account); if (transferShow) { dbSnapshot.BindTransfer2Account(account.address, account.index, Reward.hash); } } LuaVMEnv luaVMEnv = Entity.Root.GetComponent <LuaVMEnv>();
public bool ApplyTransfer(DbSnapshot dbSnapshot, Transfer transfer, long height) { if (transfer.type != "tranfer") { return(true); } if (transfer.addressIn == transfer.addressOut) { return(true); } if (BigInt.Less(transfer.amount, "0", true)) { return(true); } //if (!transfer.CheckSign() && height != 1) // return true; if (height != 1) { Account accountIn = dbSnapshot.Accounts.Get(transfer.addressIn); if (accountIn == null) { return(true); } if (BigInt.Less(accountIn.amount, transfer.amount, false)) { return(true); } if (accountIn.nonce + 1 != transfer.nonce) { return(true); } accountIn.amount = BigInt.Add(accountIn.amount, transfer.amount); accountIn.index += 1; accountIn.nonce += 1; dbSnapshot.Accounts.Add(accountIn.address, accountIn); if (transferShow) { dbSnapshot.BindTransfer2Account(transfer.addressIn, accountIn.index, transfer.hash); } } Account accountOut = dbSnapshot.Accounts.Get(transfer.addressOut); if (accountOut == null) { accountOut = new Account() { address = transfer.addressOut, amount = "0", index = 0, nonce = 0 } } ; accountOut.amount = BigInt.Add(accountOut.amount, transfer.amount); accountOut.index += 1; dbSnapshot.Accounts.Add(accountOut.address, accountOut); if (transferShow) { dbSnapshot.BindTransfer2Account(transfer.addressOut, accountOut.index, transfer.hash); transfer.height = height; dbSnapshot.Transfers.Add(transfer.hash, transfer); } return(true); }