コード例 #1
0
        public override async Task <OperationResult <object> > GetVerifyTransaction(AuthorizedModel model, CancellationToken ct)
        {
            if (!TryReconnectChain(ct))
            {
                return(new OperationResult <object>(new AppError(LocalizationKeys.EnableConnectToBlockchain)));
            }

            var keys = ToKeyArr(model.PostingKey);

            if (keys == null)
            {
                return(new OperationResult <object>(new AppError(LocalizationKeys.WrongPrivatePostingKey)));
            }

            return(await Task.Run(() =>
            {
                var op = new FollowOperation(model.Login, "steepshot", DitchFollowType.Blog, model.Login);
                var properties = new DynamicGlobalPropertyObject
                {
                    HeadBlockId = Hex.ToString(_operationManager.ChainId),
                    Time = DateTime.Now,
                    HeadBlockNumber = 0
                };
                var tr = _operationManager.CreateTransaction(properties, keys, ct, op);
                return new OperationResult <object>()
                {
                    Result = tr
                };
            }, ct));
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="propertyApiObj"></param>
        /// <param name="userPrivateKeys"></param>
        /// <param name="token">Throws a <see cref="T:System.OperationCanceledException" /> if this token has had cancellation requested.</param>
        /// <param name="operations"></param>
        /// <returns></returns>
        /// <exception cref="T:System.OperationCanceledException">The token has had cancellation requested.</exception>
        public Task <SignedTransaction> CreateTransactionAsync(DynamicGlobalPropertyObject propertyApiObj, IList <byte[]> userPrivateKeys, BaseOperation[] operations, CancellationToken token)
        {
            return(Task.Run(() =>
            {
                var transaction = new SignedTransaction
                {
                    ChainId = ChainId,
                    RefBlockNum = (ushort)(propertyApiObj.HeadBlockNumber & 0xffff),
                    RefBlockPrefix = (uint)BitConverter.ToInt32(Hex.HexToBytes(propertyApiObj.HeadBlockId), 4),
                    Expiration = propertyApiObj.Time.Value.AddSeconds(30),
                    Operations = operations.Select(o => new Operation(o)).ToArray()
                };

                var msg = MessageSerializer.Serialize <SignedTransaction>(transaction);
                var data = Sha256Manager.GetHash(msg);

                transaction.Signatures = new string[userPrivateKeys.Count];
                for (var i = 0; i < userPrivateKeys.Count; i++)
                {
                    token.ThrowIfCancellationRequested();
                    var userPrivateKey = userPrivateKeys[i];
                    var sig = Secp256K1Manager.SignCompressedCompact(data, userPrivateKey);
                    transaction.Signatures[i] = Hex.ToString(sig);
                }

                return transaction;
            }, token));
        }
コード例 #3
0
        public override async Task <OperationResult <string> > GetVerifyTransaction(AuthorizedPostingModel model, CancellationToken ct)
        {
            var isConnected = await TryReconnectChain(ct);

            if (!isConnected)
            {
                return(new OperationResult <string>(new ValidationException(LocalizationKeys.EnableConnectToBlockchain)));
            }

            var keys = ToKeyArr(model.PostingKey);

            if (keys == null)
            {
                return(new OperationResult <string>(new ValidationException(LocalizationKeys.WrongPrivatePostingKey)));
            }

            var op         = new FollowOperation(model.Login, "steepshot", Ditch.Golos.Models.FollowType.Blog, model.Login);
            var properties = new DynamicGlobalPropertyObject
            {
                HeadBlockId     = "0000000000000000000000000000000000000000",
                Time            = DateTime.Now,
                HeadBlockNumber = 0
            };
            var tr = await _operationManager.CreateTransaction(properties, keys, op, ct);

            return(new OperationResult <string> {
                Result = JsonConvert.SerializeObject(tr)
            });
        }
コード例 #4
0
ファイル: OperationManager.cs プロジェクト: PlumpMath/Ditch
        /// <summary>
        /// Execute custom user method
        /// Возвращает TRUE если транзакция подписана правильно
        /// </summary>
        /// <param name="userPrivateKeys"></param>
        /// <param name="token">Throws a <see cref="T:System.OperationCanceledException" /> if this token has had cancellation requested.</param>
        /// <param name="testOps"></param>
        /// <returns></returns>
        /// <exception cref="T:System.OperationCanceledException">The token has had cancellation requested.</exception>
        public JsonRpcResponse <bool> VerifyAuthority(IEnumerable <byte[]> userPrivateKeys, CancellationToken token, params BaseOperation[] testOps)
        {
            var prop = new DynamicGlobalPropertyObject {
                HeadBlockId = "0000000000000000000000000000000000000000", Time = DateTime.Now, HeadBlockNumber = 0
            };
            var transaction = CreateTransaction(prop, userPrivateKeys, token, testOps);

            return(VerifyAuthority(transaction, token));
        }
コード例 #5
0
ファイル: OperationManager.cs プロジェクト: cogutvalera/Ditch
        /// <summary>
        /// Execute custom user method
        /// Возвращает TRUE если транзакция подписана правильно
        /// </summary>
        /// <param name="userPrivateKeys"></param>
        /// <param name="token">Throws a <see cref="T:System.OperationCanceledException" /> if this token has had cancellation requested.</param>
        /// <param name="testOps"></param>
        /// <returns></returns>
        /// <exception cref="T:System.OperationCanceledException">The token has had cancellation requested.</exception>
        public async Task <JsonRpcResponse <bool> > VerifyAuthority(IList <byte[]> userPrivateKeys, BaseOperation[] testOps, CancellationToken token)
        {
            var prop = new DynamicGlobalPropertyObject {
                HeadBlockId = "0000000000000000000000000000000000000000", Time = DateTime.Now, HeadBlockNumber = 0
            };
            var transaction = await CreateTransaction(prop, userPrivateKeys, testOps, token);

            return(await VerifyAuthority(transaction, token));
        }
コード例 #6
0
ファイル: OperationManager.cs プロジェクト: PlumpMath/Ditch
        /// <summary>
        ///
        /// </summary>
        /// <param name="propertyApiObj"></param>
        /// <param name="userPrivateKeys"></param>
        /// <param name="token">Throws a <see cref="T:System.OperationCanceledException" /> if this token has had cancellation requested.</param>
        /// <param name="operations"></param>
        /// <returns></returns>
        /// <exception cref="T:System.OperationCanceledException">The token has had cancellation requested.</exception>
        public SignedTransaction CreateTransaction(DynamicGlobalPropertyObject propertyApiObj, IEnumerable <byte[]> userPrivateKeys, CancellationToken token, params BaseOperation[] operations)
        {
            var transaction = new SignedTransaction
            {
                ChainId        = ChainId,
                RefBlockNum    = (ushort)(propertyApiObj.HeadBlockNumber & 0xffff),
                RefBlockPrefix = (uint)BitConverter.ToInt32(Hex.HexToBytes(propertyApiObj.HeadBlockId), 4),
                Expiration     = propertyApiObj.Time.AddSeconds(30),
                BaseOperations = operations
            };

            var msg  = SerializeHelper.TransactionToMessage(transaction, Version);
            var data = Secp256k1Manager.GetMessageHash(msg);

            foreach (var userPrivateKey in userPrivateKeys)
            {
                token.ThrowIfCancellationRequested();
                var sig = Secp256k1Manager.SignCompressedCompact(data, userPrivateKey);
                transaction.Signatures.Add(sig);
            }

            return(transaction);
        }
コード例 #7
0
 public Task <SignedTransaction> CreateTransactionAsync(DynamicGlobalPropertyObject propertyApiObj, IList <byte[]> userPrivateKeys, BaseOperation operation, CancellationToken token)
 {
     return(CreateTransactionAsync(propertyApiObj, userPrivateKeys, new[] { operation }, token));
 }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="propertyApiObj"></param>
        /// <param name="userPrivateKeys"></param>
        /// <param name="token">Throws a <see cref="T:System.OperationCanceledException" /> if this token has had cancellation requested.</param>
        /// <param name="operations"></param>
        /// <returns></returns>
        /// <exception cref="T:System.OperationCanceledException">The token has had cancellation requested.</exception>
        public SignedTransaction CreateTransaction(DynamicGlobalPropertyObject propertyApiObj, IList <byte[]> userPrivateKeys, CancellationToken token, params BaseOperation[] operations)
        {
            var transaction = new SignedTransaction
            {
                //ChainId = ChainId,
                RefBlockNum    = (ushort)(propertyApiObj.HeadBlockNumber & 0xffff),
                RefBlockPrefix = (uint)BitConverter.ToInt32(Hex.HexToBytes(propertyApiObj.HeadBlockId), 4),
                Expiration     = propertyApiObj.Time.AddSeconds(30),
                BaseOperations = operations
            };

            var reqRez = GetRequiredFees(transaction.BaseOperations, (operations[0] as AccountCreateOperation).Fee.AssetId, CancellationToken.None);

            if (!reqRez.IsError)
            {
                (operations[0] as AccountCreateOperation).Fee.Amount = JsonConvert.DeserializeObject <RequiredFees>(reqRez.Result[0].ToString()).amount * 5000;
            }

            VerifyAccountAuthority(
                "nano-blockchain",
                new PublicKeyType[] {
                new PublicKeyType("TEST6HWVwXazrgS3MsWZvvSV6qdRbc8GS7KpdfDw8mAcNug4RcPv3v"),
                //new PublicKeyType("TEST7AX8Ewg85sudNVfwqGcCDEAGnhwyVMgvrWW6bkQT5aDm5fdELM")
            },
                CancellationToken.None
                );

            GetPotentialSignatures(transaction, CancellationToken.None);

            GetRequiredSignatures(
                transaction,
                new PublicKeyType[] {
                new PublicKeyType("TEST6HWVwXazrgS3MsWZvvSV6qdRbc8GS7KpdfDw8mAcNug4RcPv3v"),
                new PublicKeyType("TEST7AX8Ewg85sudNVfwqGcCDEAGnhwyVMgvrWW6bkQT5aDm5fdELM")
            },
                CancellationToken.None
                );

            var remoteHex = Hex.HexToBytes(GetTransactionHex(transaction, CancellationToken.None).Result);
            var localHex  = MessageSerializer.Serialize <SignedTransaction>(transaction);

            string strRez = string.Empty;
            int    limit;

            if (remoteHex.Length > localHex.Length)
            {
                limit = remoteHex.Length;
            }
            else
            {
                limit = localHex.Length;
            }

            for (int i = 0; i < limit; i++)
            {
                if (i >= remoteHex.Length || i >= localHex.Length)
                {
                    if (remoteHex.Length > localHex.Length)
                    {
                        strRez += "[" + i.ToString() + "] " + Hex.HexToInteger(new byte[] { remoteHex[i] }).ToString() + "\n";
                    }
                    else
                    {
                        strRez += "[" + i.ToString() + "]     " + Hex.HexToInteger(new byte[] { localHex[i] }).ToString() + "\n";
                    }
                }
                else
                {
                    strRez += "[" + i.ToString() + "] " + Hex.HexToInteger(new byte[] { remoteHex[i] }).ToString() + " " + Hex.HexToInteger(new byte[] { localHex[i] }).ToString() + "\n";
                }
            }

            UnityEngine.Debug.Log(strRez);
            UnityEngine.Debug.Log("LOCAL HEX =  " + Hex.ToString(localHex));
            UnityEngine.Debug.Log("REMOTE HEX = " + Hex.ToString(remoteHex));

            //for (int i = 0; i < localHex.Length; i++)
            //{
            //    localHex[i] = 0;
            //}

            var data = Sha256Manager.GetHash(Hex.Join(ChainId, localHex));

            transaction.Signatures = new string[userPrivateKeys.Count];
            for (int i = 0; i < userPrivateKeys.Count; i++)
            {
                token.ThrowIfCancellationRequested();
                var userPrivateKey = userPrivateKeys[i];
                var sig            = Secp256K1Manager.SignCompressedCompact(data, userPrivateKey);

                transaction.Signatures[i] = Hex.ToString(sig);
            }

            return(transaction);
        }