コード例 #1
0
        public void OnBeRuler(HttpMessage httpMessage)
        {
            var consensus = Entity.Root.GetComponent <Consensus>();
            var blockMgr  = Entity.Root.GetComponent <BlockMgr>();

            // 判断当前块高度是否接近主线
            if (blockMgr.newBlockHeight - consensus.transferHeight > 1000)
            {
                httpMessage.result = $"{consensus.transferHeight}:{blockMgr.newBlockHeight} The current block height is too low. command BeRuler have been ignore.";
                return;
            }

            WalletKey key = Wallet.GetWallet().GetCurWallet();

            var  address = key.ToAddress();
            long notice  = 1;

            using (var dbSnapshot = Entity.Root.GetComponent <LevelDBStore>().GetSnapshot(0))
            {
                var account = dbSnapshot.Accounts.Get(address);
                if (account != null)
                {
                    notice = account.nonce + 1;
                }
            }

            BlockSub transfer = new BlockSub();

            transfer.addressIn  = address;
            transfer.addressOut = consensus.consAddress;
            transfer.amount     = "0";
            transfer.nonce      = notice;
            transfer.type       = "contract";

            LuaVMCall luaVMCall = new LuaVMCall();

            luaVMCall.fnName   = "add";
            luaVMCall.args     = new FieldParam[0];
            transfer.data      = luaVMCall.Encode();
            transfer.timestamp = TimeHelper.Now();
            transfer.hash      = transfer.ToHash();
            transfer.sign      = transfer.ToSign(key);

            var rel = Entity.Root.GetComponent <Rule>().AddTransfer(transfer);

            if (rel == -1)
            {
                OnTransferAsync(transfer);
            }
            httpMessage.result = $"accepted transfer:{transfer.hash}";
        }
コード例 #2
0
ファイル: HttpRpc.cs プロジェクト: yuop2002cn/IOBft
        public void OnBeRuler(HttpMessage httpMessage)
        {
            Consensus consensus = Entity.Root.GetComponent <Consensus>();
            WalletKey key       = Wallet.GetWallet().GetCurWallet();

            var  address = key.ToAddress();
            long notice  = 1;

            using (var dbSnapshot = Entity.Root.GetComponent <LevelDBStore>().GetSnapshot(0))
            {
                var account = dbSnapshot.Accounts.Get(address);
                if (account != null)
                {
                    notice = account.notice + 1;
                }
            }

            Transfer transfer = new Transfer();

            transfer.addressIn  = address;
            transfer.addressOut = consensus.consAddress;
            transfer.amount     = "0";
            transfer.notice     = notice;
            transfer.type       = "contract";

            LuaVMCall luaVMCall = new LuaVMCall();

            luaVMCall.fnName = "Add";
            luaVMCall.args   = new FieldParam[0];
            //luaVMCall.args[0] = new FieldParam();
            //luaVMCall.args[0].type = "Int64";
            //luaVMCall.args[0].value = "999";
            //long aaa = (long)luaVMCall.args[0].GetValue();
            transfer.data = luaVMCall.Encode();

            transfer.hash = transfer.ToHash();
            transfer.sign = transfer.ToSign(key);

            var rel = Entity.Root.GetComponent <Rule>().AddTransfer(transfer);

            if (rel == -1)
            {
                OnTransferAsync(transfer);
            }
            httpMessage.result = $"accepted transfer:{transfer.hash}";
        }