コード例 #1
0
 public static string itoa(int value, int @base)
 {
     return(StdLib.Itoa(value, @base));
 }
コード例 #2
0
 public static string Serialize(object obj)
 {
     return(StdLib.JsonSerialize(obj));
 }
コード例 #3
0
 public void PutObject(byte[] key, object value)
 {
     Put(key, StdLib.Serialize(value));
 }
コード例 #4
0
 public T Get <T>(byte[] key) where T : class, new()
 {
     return((T)StdLib.Deserialize(Get(key)));
 }
コード例 #5
0
 public void Put <T>(byte[] key, T value) where T : class, new()
 {
     Put(key, StdLib.Serialize(value));
 }
コード例 #6
0
ファイル: Auction.cs プロジェクト: cleancoindev/auction
 // Get the key for userLots mapping
 private string GetUserLotKey(Bytes address, long number)
 {
     return(StdLib.BytesToHex(address) + System.Convert.ToString(number));
 }
コード例 #7
0
ファイル: Auction.cs プロジェクト: cleancoindev/auction
 // Get the key for assetLots mapping
 private string GetAssetLotKey(long gameId, Bytes classId, long number)
 {
     return(System.Convert.ToString(gameId) + StdLib.BytesToHex(classId) + System.Convert.ToString(number));
 }
コード例 #8
0
 public static byte[] base64Decode(string input)
 {
     return((byte[])StdLib.Base64Decode(input));
 }
コード例 #9
0
 public static string[] stringSplit2(string str, string separator, bool removeEmptyEntries)
 {
     return(StdLib.StringSplit(str, separator, removeEmptyEntries));
 }
コード例 #10
0
 public static int memorySearch3(ByteString mem, ByteString value, int start, bool backward)
 {
     return(StdLib.MemorySearch(mem, value, start, backward));
 }
コード例 #11
0
 public static string[] stringSplit1(string str, string separator)
 {
     return(StdLib.StringSplit(str, separator));
 }
コード例 #12
0
 public static int memorySearch2(ByteString mem, ByteString value, int start)
 {
     return(StdLib.MemorySearch(mem, value, start));
 }
コード例 #13
0
 public static int memorySearch1(ByteString mem, ByteString value)
 {
     return(StdLib.MemorySearch(mem, value));
 }
コード例 #14
0
 public static int memoryCompare(ByteString str1, ByteString str2)
 {
     return(StdLib.MemoryCompare(str1, str2));
 }
コード例 #15
0
ファイル: CCMC.cs プロジェクト: neo-ngd/n3-asset
        public static bool verifyAndExecuteTx(byte[] proof, byte[] RawHeader, byte[] headerProof, byte[] currentRawHeader, byte[] signList)
        {
            Header txheader;

            try
            {
                txheader = deserializHeader(RawHeader);
            }
            catch
            {
                notify("Header deserialize failed");
                throw new Exception();
            }
            ECPoint[]  keepers            = (ECPoint[])StdLib.Deserialize(Storage.Get(Storage.CurrentContext, mCKeeperPubKeysPrefix));
            int        n                  = keepers.Length;
            int        m                  = n - (n - 1) / 3;
            BigInteger currentEpochHeight = (BigInteger)Storage.Get(Storage.CurrentContext, currentEpochHeightPrefix);

            byte[] StateRootValue = new byte[] { 0x00 };
            if (txheader.height >= currentEpochHeight)
            {
                notify("New Tx executing");
                if (!verifySigWithOrder(RawHeader, signList, keepers))
                {
                    notify("Verify RawHeader signature failed!");
                    return(false);
                }
            }
            else
            {
                notify("Old Tx");
                Header currentHeader;
                if (!verifySigWithOrder(currentRawHeader, signList, keepers))
                {
                    notify("Verify currentRawHeader signature failed!");
                    return(false);
                }
                try
                {
                    currentHeader = deserializHeader(currentRawHeader);
                }
                catch
                {
                    notify("CR Header deserialize Failed");
                    throw new Exception();
                }
                StateRootValue = merkleProve(headerProof, currentHeader.blockRoot);
                ByteString RawHeaderHash = (ByteString)Hash256(RawHeader);
                if (!StateRootValue.Equals(RawHeaderHash))
                {
                    notify("Verify block proof signature failed!");
                    return(false);
                }
            }
            // Through rawHeader.CrossStateRoot, the toMerkleValue or cross chain msg can be verified and parsed from proof
            StateRootValue = merkleProve(proof, txheader.crossStatesRoot);
            ToMerkleValue merkleValue = deserializMerkleValue(StateRootValue);

            //check by txid
            if ((BigInteger)Storage.Get(Storage.CurrentContext, transactionPrefix.Concat(merkleValue.fromChainID).Concat(merkleValue.txHash)) == 1)
            {
                notify("Transaction has been executed");
                return(false);
            }
            //check to chainID
            if ((ByteString)merkleValue.TxParam.toChainID != (ByteString)chainID)
            {
                notify((ByteString)merkleValue.TxParam.toChainID);
                notify((ByteString)chainID);
                notify("Not Neo crosschain tx");
                return(false);
            }
            //run croos chain tx
            if (ExecuteCrossChainTx(merkleValue))
            {
                notify("Tx execute success");
            }
            else
            {
                notify("Tx execute fail");
                return(false);
            }

            //event
            CrossChainUnlockEvent(merkleValue.fromChainID, merkleValue.TxParam.toContract, merkleValue.txHash);
            return(true);
        }
コード例 #16
0
 public object GetObject(ByteString key)
 {
     return(StdLib.Deserialize(Get(key)));
 }
コード例 #17
0
 public unsafe static void BulkCopy(byte *dest, byte *src, int n)
 {
     StdLib.memcpy(dest, src, n);
 }
コード例 #18
0
 public object GetObject(byte[] key)
 {
     return(StdLib.Deserialize(Get(key)));
 }
コード例 #19
0
ファイル: Auction.cs プロジェクト: cleancoindev/auction
 // Get the key for assetLotsCount mapping
 private string GetAssetCountKey(long gameId, Bytes classId)
 {
     return(System.Convert.ToString(gameId) + StdLib.BytesToHex(classId));
 }
コード例 #20
0
ファイル: stdlib.cs プロジェクト: caffeinum/pravda
 public bool ValidateEd25519Signature(Bytes pubKey, String message, Bytes sign)
 {
     return(StdLib.ValidateEd25519Signature(pubKey, message, sign));
 }
コード例 #21
0
ファイル: poker.cs プロジェクト: Chicker/pravda
    private string showdown(string cardSalt, Bytes dealtCards)
    {
        Bytes playersCountB = Players.getDefault(-1, new Bytes(0));
        int   playersCount  = playersCountB[0];
        int   dealt         = playersCount * 2 + TableCards.getDefault(-1, 0);

        if (dealt != Convert.ToInt32(dealtCards[0])) // length
        // should be a built-in error
        {
            return("count mismatch! was: " + Convert.ToString(dealt) + " got: " + Convert.ToString(dealtCards[0])); // showdown can't be verified!
        }
        for (int i = 0; i < dealt; i++)
        {
            int   card     = Convert.ToInt32(dealtCards[i + 1]);
            Bytes cardHash = StdLib.Ripemd160(cardSalt + Convert.ToString(card));
            if (i < (playersCount * 2))
            {
                Bytes playerCardHash;
                Bytes p = Players.get(i % playersCount);
                if (i < playersCount)
                {
                    playerCardHash = PlayerCards1.getDefault(p, Bytes.EMPTY);
                }
                else
                {
                    playerCardHash = PlayerCards2.getDefault(p, Bytes.EMPTY);
                }

                if (playerCardHash != cardHash)
                {
                    return("cards mismatch! #" + Convert.ToString(i) + " (" + Convert.ToString(card) + ") expected: " + Convert.ToString(playerCardHash) + " got: " + Convert.ToString(cardHash));
                }
            }
        }
        // give winners their chips
        int totalWin = 0;

        for (int i = 0; i < playersCount; i++)
        {
            Bytes player = Players.getDefault(i, Bytes.EMPTY);
            int   bet    = Bets.getDefault(player, 0);
            totalWin = totalWin + bet;
            int bank = Bankrolls.getDefault(player, 0);
            Bankrolls.put(player, bank - bet);
        }
        int   maxHand = 0;
        Bytes winner  = Bytes.EMPTY;

        for (int i = 0; i < playersCount; i++)
        {
            Bytes player = Players.getDefault(i, Bytes.EMPTY);
            bool  fold   = Folded.getDefault(player, false);
            if (!fold)
            {
                int[] cards = new int[] {
                    Convert.ToInt32(PlayerCards1.getDefault(player, Bytes.EMPTY)[0]),
                    Convert.ToInt32(PlayerCards2.getDefault(player, Bytes.EMPTY)[0]),
                    TableCards.getDefault(0, -1),
                    TableCards.getDefault(1, -1),
                    TableCards.getDefault(2, -1),
                    TableCards.getDefault(3, -1),
                    TableCards.getDefault(4, -1),
                };

                int temp = 0;
                for (int write = 0; write < 7; write++)
                {
                    for (int sort = 0; sort < 7 - write - 1; sort++)
                    {
                        int val1 = getValue(cards[sort]);
                        int val2 = getValue(cards[sort + 1]);
                        if (val1 > val2)
                        {
                            temp            = cards[sort + 1];
                            cards[sort + 1] = cards[sort];
                            cards[sort]     = temp;
                        }
                    }
                }

                int best = getHighestCombination(cards[0], cards[1], cards[2], cards[3], cards[4], cards[5], cards[6]);
                if (best > maxHand)
                {
                    maxHand = best;
                    winner  = player;
                }
            }
        }
        // winner
        if (winner == Bytes.EMPTY)
        {
            return("couldn't find winner!");
        }

        int wbank = Bankrolls.getDefault(winner, 0);

        Bankrolls.put(winner, wbank + totalWin);

        return("success!");
    }
コード例 #22
0
ファイル: stdlib.cs プロジェクト: caffeinum/pravda
 public Bytes Ripemd160(String input)
 {
     return(StdLib.Ripemd160(input));
 }
コード例 #23
0
 public void Put <T>(ByteString key, T value) where T : class, new()
 {
     Put(key, StdLib.Serialize(value));
 }
コード例 #24
0
ファイル: program.cs プロジェクト: baadev/gamenode
    private int rarityOfChest()
    {
        int rarityValue = ((System.Convert.ToInt32(Info.Sender()) * System.Convert.ToInt32(StdLib.Ripemd160(System.Convert.ToString(commonChests + rareChests + epicChests + legendaryChests + 1))))) % 100;

        if (rarityValue < 60 && 0 < commonChests)
        {
            commonChests -= 1;
            return(1);
        }
        else if (rarityValue < 90 && 0 < rareChests)
        {
            rareChests -= 1;
            return(2);
        }
        else if (rarityValue < 99 && 0 < epicChests)
        {
            epicChests -= 1;
            return(3);
        }
        else if (0 < legendaryChests)
        {
            legendaryChests -= 1;
            return(4);
        }
        return(0);
    }
コード例 #25
0
 public static object Deserialize(string json)
 {
     return(StdLib.JsonDeserialize(json));
 }
コード例 #26
0
ファイル: program.cs プロジェクト: baadev/gamenode
    public String newChestWarrior()
    {
        Bytes  sender             = Info.Sender();
        int    balanceSender      = _balanceOf(sender);
        int    warriorCountSender = _warriorCount(sender);
        int    rarity             = rarityOfChest();
        String warriorsList       = PlayerWarriors.getDefault(sender, "");

        if (rarity > 0)
        {
            if (((CHEST_PRICE - 1) < balanceSender) && (warriorCountSender < 5))
            {
                int typeOfWarrior = (System.Convert.ToInt32(StdLib.Ripemd160(System.Convert.ToString(warriorIds))) % typesCount);
                if (typeOfWarrior < 0)
                {
                    typeOfWarrior = 0;
                }
                else
                if (typeOfWarrior > typesCount - 1)
                {
                    typeOfWarrior = typesCount - 1;
                }

                String warriorName = System.Convert.ToString(warriorIds) + (System.Convert.ToString(typeOfWarrior) + ".");

                if (typeOfWarrior == 0)
                {
                    int str   = 3 * rarity;
                    int endur = 5 * rarity;
                    int agil  = 3 * rarity;
                    int luck  = 2 * rarity;
                    privateSetupWarriorAttributes(warriorName, str, endur, agil, luck);
                    WarriorType.put(warriorName, 0);
                    WarriorLvl.put(warriorName, 0);
                    WarriorId.put(warriorName, warriorIds);
                }
                else
                if (typeOfWarrior == 1)
                {
                    int str   = 1 * rarity;
                    int endur = 2 * rarity;
                    int agil  = 4 * rarity;
                    int luck  = 3 * rarity;
                    privateSetupWarriorAttributes(warriorName, str, endur, agil, luck);
                    WarriorType.put(warriorName, 1);
                    WarriorLvl.put(warriorName, 0);
                    WarriorId.put(warriorName, warriorIds);
                }
                else
                if (typeOfWarrior == 2)
                {
                    int str   = 5 * rarity;
                    int endur = 3 * rarity;
                    int agil  = 1 * rarity;
                    int luck  = 4 * rarity;
                    privateSetupWarriorAttributes(warriorName, str, endur, agil, luck);
                    WarriorType.put(warriorName, 2);
                    WarriorLvl.put(warriorName, 0);
                    WarriorId.put(warriorName, warriorIds);
                }

                if (warriorCountSender == 0)
                {
                    warriorsList = warriorName;
                }
                else
                {
                    warriorsList = warriorsList + warriorName;
                }

                warriorIds         += 1;
                warriorCountSender += 1;
                int newPlayerBalance = balanceSender - CHEST_PRICE;

                WarriorRare.put(warriorName, rarity);
                PlayerWarriorCount.put(sender, warriorCountSender);
                PlayerBalance.put(sender, newPlayerBalance);
                WarriorToOwner.put(warriorName, sender);
                PlayerWarriors.put(sender, warriorsList);

                return("Success givving new warrior from chest.");
            }
            return("Too much warriors.");
        }
        else
        {
            return("Out of stock.");
        }
    }
コード例 #27
0
 public void PutObject(ByteString key, object value)
 {
     Put(key, StdLib.Serialize(value));
 }
コード例 #28
0
ファイル: CCMC.cs プロジェクト: neo-ngd/n3-asset
 public static object getBookKeepers()
 {
     ECPoint[] keepers = (ECPoint[])StdLib.Deserialize(Storage.Get(Storage.CurrentContext, mCKeeperPubKeysPrefix));
     return(keepers);
 }
コード例 #29
0
        public bool ReadOneTransaction(StorageEnvironmentOptions options, bool checkCrc = true)
        {
            if (_readingPage >= _pager.NumberOfAllocatedPages)
            {
                return(false);
            }

            TransactionHeader *current;

            if (!TryReadAndValidateHeader(options, out current))
            {
                return(false);
            }

            var compressedPages = (current->CompressedSize / AbstractPager.PageSize) + (current->CompressedSize % AbstractPager.PageSize == 0 ? 0 : 1);

            if (current->TransactionId <= _lastSyncedTransactionId)
            {
                LastTransactionHeader = current;
                _readingPage         += compressedPages;
                return(true); // skipping
            }

            if (checkCrc && !ValidatePagesCrc(options, compressedPages, current))
            {
                return(false);
            }

            _recoveryPager.EnsureContinuous(null, _recoveryPage, (current->PageCount + current->OverflowPageCount) + 1);
            var dataPage = _recoveryPager.AcquirePagePointer(_recoveryPage);

            StdLib.memset(dataPage, 0, (current->PageCount + current->OverflowPageCount) * AbstractPager.PageSize);
            try
            {
                LZ4.Decode64(_pager.AcquirePagePointer(_readingPage), current->CompressedSize, dataPage, current->UncompressedSize, true);
            }
            catch (Exception e)
            {
                options.InvokeRecoveryError(this, "Could not de-compress, invalid data", e);
                RequireHeaderUpdate = true;

                return(false);
            }

            var tempTransactionPageTranslaction = new Dictionary <long, PagePosition>();

            for (var i = 0; i < current->PageCount; i++)
            {
                Debug.Assert(_pager.Disposed == false);
                Debug.Assert(_recoveryPager.Disposed == false);

                var page = _recoveryPager.Read(_recoveryPage);

                tempTransactionPageTranslaction[page.PageNumber] = new PagePosition
                {
                    JournalPos    = _recoveryPage,
                    TransactionId = current->TransactionId
                };

                if (page.IsOverflow)
                {
                    var numOfPages = _recoveryPager.GetNumberOfOverflowPages(page.OverflowSize);
                    _recoveryPage += numOfPages;
                }
                else
                {
                    _recoveryPage++;
                }
            }

            _readingPage += compressedPages;

            LastTransactionHeader = current;

            foreach (var pagePosition in tempTransactionPageTranslaction)
            {
                _transactionPageTranslation[pagePosition.Key] = pagePosition.Value;
            }

            return(true);
        }
コード例 #30
0
 public static object atoi(string value, int @base)
 {
     return(StdLib.Atoi(value, @base));
 }