public async Task CreateCollectionEmitsEvent()
        {
            var collectionName        = "1111";
            var collectionDescription = "1111";
            var tokenPrefix           = "1111";
            var mode = new CollectionMode(new Nft(200));

            var collectionCreatedTask = new TaskCompletionSource <Created>();
            var createCollection      = new CreateCollection(collectionName, collectionDescription, tokenPrefix, mode);

            using var blockClient = CreateClient();
            blockClient.CollectionManagement.CollectionCreated += (sender, @event) =>
            {
                if (AddressUtils.GetAddrFromPublicKey(@event.Account).Equals(Configuration.Alice.Address))
                {
                    collectionCreatedTask.SetResult(@event);
                }
            };

            using var client = CreateClient();
            client.CollectionManagement.CreateCollection(createCollection, new Address(Configuration.Alice.Address), Configuration.Alice.PrivateKey);

            await collectionCreatedTask.Task
            .WithTimeout(TimeSpan.FromMinutes(1));

            var created = collectionCreatedTask.Task.Result;

            Assert.NotNull(created);
            Output.WriteLine($"Created collection with id: {created.Id}");
        }
示例#2
0
        public override async Task Process(NftIncomingTransaction transaction)
        {
            var account = AddressUtils.GetAddrFromPublicKey(new PublicKey()
            {
                Bytes = transaction.OwnerPublicKeyBytes
            });

            _logger.LogInformation("Calling Matcher.RegisterNftDeposit({Account}, {CollectionId}, {TokenId})", account, transaction.CollectionId, transaction.TokenId);
            await this.CallSubstrate(_logger,
                                     _configuration.MatcherContractPublicKey,
                                     _configuration.UniqueEndpoint,
                                     new Address()
            {
                Symbols = _configuration.MarketplaceUniqueAddress
            },
                                     _configuration.MarketplacePrivateKeyBytes,
                                     app => this.ContractCall(app, () => new RegisterNftDepositParameter()
            {
                User = new PublicKey()
                {
                    Bytes = transaction.OwnerPublicKeyBytes
                },
                CollectionId = transaction.CollectionId,
                TokenId      = transaction.TokenId
            }));

            _logger.LogInformation("Successfully called Matcher.RegisterNftDeposit({Account}, {CollectionId}, {TokenId})", account, transaction.CollectionId, transaction.TokenId);
        }
示例#3
0
        public override async Task Process(QuoteIncomingTransaction quoteIncoming)
        {
            var account = AddressUtils.GetAddrFromPublicKey(new PublicKey()
            {
                Bytes = quoteIncoming.AccountPublicKeyBytes
            });

            _logger.LogInformation("Calling Matcher.RegisterDeposit({Account}, {Balance}, {QuoteId})", account, quoteIncoming.Amount, quoteIncoming.QuoteId);
            await this.CallSubstrate(_logger,
                                     _configuration.MatcherContractPublicKey,
                                     _configuration.UniqueEndpoint,
                                     new Address()
            {
                Symbols = _configuration.MarketplaceUniqueAddress
            },
                                     _configuration.MarketplacePrivateKeyBytes,
                                     app => this.ContractCall(app, () => new RegisterDepositParameter()
            {
                User = new PublicKey()
                {
                    Bytes = quoteIncoming.AccountPublicKeyBytes
                },
                DepositBalance = new Balance()
                {
                    Value = quoteIncoming.Amount
                },
                QuoteId = quoteIncoming.QuoteId
            }));

            _logger.LogInformation("Successfully called Matcher.RegisterDeposit({Account}, {Balance}, {QuoteId})", account, quoteIncoming.Amount, quoteIncoming.QuoteId);
        }
        internal async Task LoadDataAsync()
        {
            IsBusy = true;
            try
            {
                await Task.Run(() =>
                {
                    try
                    {
                        var storedShipment = GetShipment(ShipmentId);
                        var products       = new List <ProductInfo>();
                        foreach (var productId in storedShipment.Products.ProductIds)
                        {
                            var storedProduct = GetProduct(productId.ToString());
                            products.Add(new ProductInfo
                            {
                                ProductId = productId.ToString(),
                                Owner     = AddressUtils.GetAddrFromPublicKey(storedProduct.Owner),
                                Props     = storedProduct.PropList.IsT1
                                    ? storedProduct.PropList.AsT1.Props.Select(p =>
                                                                               new ProductPropertyInfo {
                                    Name = p.Name.ToString(), Value = p.Value.ToString()
                                }).ToArray()
                                    : new ProductPropertyInfo[0],
                                Registered = DateTimeOffset.FromUnixTimeMilliseconds(storedProduct.Registered).LocalDateTime,
                            });
                        }

                        Device.BeginInvokeOnMainThread(() =>
                        {
                            Shipment =
                                new ShipmentInfo
                            {
                                ShipmentId = ShipmentId,
                                Owner      = AddressUtils.GetAddrFromPublicKey(storedShipment.Owner),
                                Status     = storedShipment.Status.Value.ToString(),
                                Products   = products.ToArray(),
                                Registered = DateTimeOffset.FromUnixTimeMilliseconds(storedShipment.Registered).LocalDateTime,
                                Delivered  = storedShipment.Delivered.IsT1
                                        ? DateTimeOffset.FromUnixTimeMilliseconds((long)storedShipment.Delivered.Value).LocalDateTime
                                        : (DateTime?)null
                            };
                            ShipmentOperationsVisible = true;
                        });
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex);
                        Toast.ShowShortToast("Error loading shipment.");
                    }
                });
            }
            finally
            {
                IsBusy = false;
            }
        }
示例#5
0
        public object Deserialize(Type type, Stream stream, IBinarySerializer deserializer, object[] parameters)
        {
            var key = new byte[32];

            stream.Read(key, 0, key.Length);

            var address = AddressUtils.GetAddrFromPublicKey(new PublicKey()
            {
                Bytes = key
            });

            return(new Address()
            {
                Symbols = address
            });
        }
示例#6
0
        public override async Task Process(NftOutgoingTransaction outgoing)
        {
            var account = AddressUtils.GetAddrFromPublicKey(new PublicKey()
            {
                Bytes = outgoing.RecipientPublicKeyBytes
            });

            _logger.LogInformation("Calling Nft.Transfer({Account}, {CollectionId}, {TokenId}, {Value})", account, outgoing.CollectionId, outgoing.TokenId, outgoing.Value);
            var recipient = new PublicKey()
            {
                Bytes = outgoing.RecipientPublicKeyBytes
            };

            await this.CallSubstrate(
                _logger,
                _configuration.MatcherContractPublicKey,
                _configuration.UniqueEndpoint,
                new Address(_configuration.MarketplaceUniqueAddress),
                _configuration.MarketplacePrivateKeyBytes,
                app => new TransferCall(recipient, (uint)outgoing.CollectionId, (uint)outgoing.TokenId, outgoing.Value));

            _logger.LogInformation("Successfully called Nft.Transfer({Account}, {CollectionId}, {TokenId}, {Value})", account, outgoing.CollectionId, outgoing.TokenId, outgoing.Value);
        }
示例#7
0
 public static string ToAddress(this PublicKey publicKey)
 {
     return(AddressUtils.GetAddrFromPublicKey(publicKey));
 }