Esempio n. 1
0
        public override async Task <OperationResult <VoteResponse> > Vote(VoteModel model, CancellationToken ct)
        {
            return(await Task.Run(() =>
            {
                if (!TryReconnectChain(ct))
                {
                    return new OperationResult <VoteResponse>(new ApplicationError(Localization.Errors.EnableConnectToBlockchain));
                }

                var keys = ToKeyArr(model.PostingKey);
                if (keys == null)
                {
                    return new OperationResult <VoteResponse>(new ApplicationError(Localization.Errors.WrongPrivatePostingKey));
                }

                short weigth = 0;
                if (model.Type == VoteType.Up)
                {
                    weigth = 10000;
                }
                if (model.Type == VoteType.Flag)
                {
                    weigth = -10000;
                }

                var op = new VoteOperation(model.Login, model.Author, model.Permlink, weigth);
                var resp = _operationManager.BroadcastOperations(keys, ct, op);

                var result = new OperationResult <VoteResponse>();
                if (!resp.IsError)
                {
                    var dt = DateTime.Now;
                    var content = _operationManager.GetContent(model.Author, model.Permlink, ct);
                    if (!content.IsError)
                    {
                        //Convert Asset type to double
                        result.Result = new VoteResponse(true)
                        {
                            NewTotalPayoutReward = content.Result.TotalPayoutValue + content.Result.CuratorPayoutValue + content.Result.PendingPayoutValue,
                            NetVotes = content.Result.NetVotes,
                            VoteTime = dt
                        };
                    }
                }
                else
                {
                    OnError(resp, result);
                }
                return result;
            }, ct));
        }
Esempio n. 2
0
        public void AccountCreate()
        {
            buttonAccountCreate.interactable = false;

            IList <byte[]> YouPrivateKeys = new List <byte[]>
            {
                Ditch.Core.Base58.DecodePrivateWif("5JMCfREHnK4x5tPjruhEHJKX6wQDVBJFzikc1wxEBQ4iFTcHgMY")
            };

            Debug.Log("PRIVATE KEY = " + Hex.ToString(privateKey));

            var privateWif = Ditch.Core.Base58.EncodePrivateWif(privateKey);

            var subWif       = Ditch.Core.Base58.GetSubWif(inputAccountName.text, privateWif, "active");
            var pk           = Ditch.Core.Base58.DecodePrivateWif(subWif);
            var activePubKey = Secp256K1Manager.GetPublicKey(pk, true);

            Debug.Log("ACTIVE PUB KEY = " + Hex.ToString(activePubKey));

            subWif = Ditch.Core.Base58.GetSubWif(inputAccountName.text, privateWif, "owner");
            pk     = Ditch.Core.Base58.DecodePrivateWif(subWif);
            var ownerPubKey = Secp256K1Manager.GetPublicKey(pk, true);

            Debug.Log("OWNER PUB KEY = " + Hex.ToString(ownerPubKey));

            var accountCreateOp = new AccountCreateOperation
            {
                Fee = new Asset()
                {
                    Amount  = 0,
                    AssetId = new AssetIdType(1, 3, 0)
                },
                Registrar       = new ObjectId(1, 2, 22765),
                Referrer        = new ObjectId(1, 2, 22765),
                ReferrerPercent = 7000,
                Name            = inputAccountName.text,
                Owner           = new Authority(new PublicKeyType(ownerPubKey)),
                Active          = new Authority(new PublicKeyType(activePubKey)),
                Options         = new AccountOptions()
                {
                    MemoKey       = new PublicKeyType(activePubKey),
                    VotingAccount = new AccountIdType(1, 2, 5),
                },
            };

            var responce = _operationManager.BroadcastOperations(YouPrivateKeys, CancellationToken.None, accountCreateOp);

            GeneratePassword();

            panelInfo.SetActive(true);
            if (responce.IsError)
            {
                textPanelInfo.text = responce.GetErrorMessage();
            }
            else
            {
                textPanelInfo.text = errors[8];
            }

            //Debug.Log("RESULT = " + responce.Result);
            //Debug.Log("ERROR = " + responce.GetErrorMessage());
        }