コード例 #1
0
        private static Wallet.AccountState DecodeAccountStateBlob(AccountStateBlob blob)
        {
            var cursor  = new CursorBuffer(blob.Blob.ToByteArray());
            var blobLen = cursor.Read32();

            var state = new Dictionary <string, byte[]>();

            for (int i = 0; i < blobLen; i++)
            {
                var keyLen    = cursor.Read32();
                var keyBuffer = new byte[keyLen];
                for (int j = 0; j < keyLen; j++)
                {
                    keyBuffer[j] = cursor.Read8();
                }

                var valueLen    = cursor.Read32();
                var valueBuffer = new byte[valueLen];
                for (int k = 0; k < valueLen; k++)
                {
                    valueBuffer[k] = cursor.Read8();
                }

                state[keyBuffer.ToHexString()] = valueBuffer;
            }

            return(Wallet.AccountState.FromBytes(state[Constant.PathValues.AccountStatePath]));
        }
コード例 #2
0
ファイル: CursorBufferTest.cs プロジェクト: zsuxiong/libranet
        public void Read32_LittleEndian()
        {
            var bytes  = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
            var cursor = new CursorBuffer(bytes, true);
            var actual = cursor.Read32();

            actual = cursor.Read32();
            actual = cursor.Read32();
            var expected = 202050057U;

            Assert.Equal(actual, expected);
        }
コード例 #3
0
ファイル: CursorBufferTest.cs プロジェクト: zsuxiong/libranet
        public void Read32()
        {
            var bytes  = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
            var cursor = new CursorBuffer(bytes, false);
            var actual = cursor.Read32();

            actual = cursor.Read32();
            actual = cursor.Read32();
            var expected = 151653132U;

            Assert.Equal(actual, expected);
        }
コード例 #4
0
        public static AccountState FromBytes(byte[] bytes)
        {
            var cursor = new CursorBuffer(bytes);

            var authenticationKeyLen = cursor.Read32();
            var authenticationKey    = cursor.ReadXBytes((int)authenticationKeyLen);
            var balance = cursor.Read64();
            var delegatedKeyRotationCapability = cursor.ReadBool();
            var delegatedWithdrawalCapability  = cursor.ReadBool();

            var receivedEventsCount = cursor.Read32();

            cursor.Read32(); // skip struct attribute sequence number
            var receivedEventsKeyLen = cursor.Read32();
            var receivedEventsKey    = cursor.ReadXBytes((int)receivedEventsKeyLen);

            var sentEventsCount = cursor.Read32();

            cursor.Read32(); // skip struct attribute sequence number
            var sentEventsKeyLen = cursor.Read32();
            var sentEventsKey    = cursor.ReadXBytes((int)sentEventsKeyLen);

            var sequenceNumber = cursor.Read64();

            var receivedEvents = new EventHandle(receivedEventsKey, receivedEventsCount);
            var sentEvents     = new EventHandle(sentEventsKey, sentEventsCount);

            return(new AccountState(authenticationKey, balance, receivedEvents, sentEvents, sequenceNumber, delegatedWithdrawalCapability, delegatedKeyRotationCapability));
        }
コード例 #5
0
ファイル: AccountState.cs プロジェクト: maijaza/libranet
        public static AccountState FromBytes(byte[] bytes)
        {
            var cursor = new CursorBuffer(bytes);

            var authenticationKeyLen = cursor.Read32();
            var authenticationKey    = cursor.ReadXBytes((int)authenticationKeyLen);
            var balance = cursor.Read64();
            var delegatedWithdrawalCapability = cursor.ReadBool();
            var receivedEventsCount           = cursor.Read64();
            var sentEventsCount = cursor.Read64();
            var sequenceNumber  = cursor.Read64();

            return(new AccountState(authenticationKey, balance, receivedEventsCount, sentEventsCount, sequenceNumber, delegatedWithdrawalCapability));
        }