Пример #1
0
        public void TestObjectHeaderGet()
        {
            var host    = "localhost:8080";
            var key     = "KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr".LoadWif();
            var cid     = ContainerID.FromBase58String("Bun3sfMBpnjKc3Tx7SdwrMxyNi8ha8JT3dhuFGvYBRTz");
            var oid     = ObjectID.FromBase58String("vWt34r4ddnq61jcPec4rVaXHg7Y7GiEYFmcTB2Qwhtx");
            var address = new Address(cid, oid);
            var client  = new Client.Client(key, host);
            var source1 = new CancellationTokenSource();

            source1.CancelAfter(TimeSpan.FromMinutes(1));
            var session = client.CreateSession(source1.Token, ulong.MaxValue);

            source1.Cancel();
            var source2 = new CancellationTokenSource();

            source2.CancelAfter(TimeSpan.FromMinutes(1));
            var o = client.GetObjectHeader(source2.Token, new ObjectHeaderParams {
                Address = address, Short = false
            }, new CallOptions {
                Ttl = 2, Session = session
            });

            Assert.AreEqual(oid, o.ObjectId);
        }
Пример #2
0
        public void TestObjectHeaderGet()
        {
            var address = new Address(cid, oid);

            using var client = new Client.Client(key, host);
            using var source = new CancellationTokenSource();
            source.CancelAfter(TimeSpan.FromMinutes(1));
            var o = client.GetObjectHeader(address, false, false, new CallOptions {
                Ttl = 1
            }, source.Token).Result;

            Console.WriteLine(o);
            Assert.AreEqual(oid, o.ObjectId);
        }
Пример #3
0
        public void TestObjectPutStorageGroup()
        {
            List <ObjectID> oids = new() { ObjectID.FromString("7Q7fPKESmRJ1VGHKcB2pB4JWVebsQzrJypwQiNLU1ekv"), ObjectID.FromString("HwfVt5i9ucjPUhRpHyxamnfTvhKtTUysCZWXcJ6YZsZ4") };

            using var client = new Client.Client(key, host);
            byte[] tzh  = null;
            ulong  size = 0;

            foreach (var oid in oids)
            {
                var address = new Address(cid, oid);
                using var source = new CancellationTokenSource();
                source.CancelAfter(TimeSpan.FromMinutes(1));
                var oo = client.GetObjectHeader(address, false, false, new CallOptions {
                    Ttl = 2
                }, source.Token).Result;
                if (tzh is null)
                {
                    tzh = oo.PayloadHomomorphicHash.Sum.ToByteArray();
                }
                else
                {
                    tzh = TzHash.Concat(new() { tzh, oo.PayloadHomomorphicHash.Sum.ToByteArray() });
                }
                size += oo.PayloadSize;
            }
            var epoch = client.Epoch().Result;

            StorageGroup.StorageGroup sg = new()
            {
                ValidationDataSize = size,
                ValidationHash     = new()
                {
                    Type = ChecksumType.Tz,
                    Sum  = ByteString.CopyFrom(tzh)
                },
                ExpirationEpoch = epoch + 100,
            };
            sg.Members.AddRange(oids);
            var obj = new FSObject
            {
                Header = new Header
                {
                    OwnerId     = OwnerID.FromScriptHash(key.PublicKey().PublicKeyToScriptHash()),
                    ContainerId = cid,
                    ObjectType  = ObjectType.StorageGroup,
                },
                Payload = ByteString.CopyFrom(sg.ToByteArray()),
            };

            using var source1 = new CancellationTokenSource();
            source1.CancelAfter(TimeSpan.FromMinutes(1));
            var session = client.CreateSession(ulong.MaxValue, context: source1.Token).Result;

            source1.Cancel();
            using var source2 = new CancellationTokenSource();
            source2.CancelAfter(TimeSpan.FromMinutes(1));
            var o = client.PutObject(obj, new CallOptions {
                Ttl = 2, Session = session
            }, source2.Token).Result;

            Console.WriteLine(o.String());
            Assert.AreNotEqual("", o.String());
        }