コード例 #1
0
        public static byte[] GetTransactionType(EMessageType eTransactionType)
        {
            switch (eTransactionType)
            {
            case EMessageType.Send:
                return(EncodeUtils.HexToByteArray("2A2C87FA"));

            case EMessageType.NewOrder:
                return(EncodeUtils.HexToByteArray("CE6DC043"));

            case EMessageType.CancelOrder:
                return(EncodeUtils.HexToByteArray("166E681B"));

            case EMessageType.TokenFreeze:
                return(EncodeUtils.HexToByteArray("E774B32D"));

            case EMessageType.TokenUnfreeze:
                return(EncodeUtils.HexToByteArray("6515FF0D"));

            case EMessageType.StdSignature:
                return(new byte[0]);

            case EMessageType.PubKey:
                return(EncodeUtils.HexToByteArray("EB5AE987"));

            case EMessageType.StdTx:
                return(EncodeUtils.HexToByteArray("F0625DEE"));

            case EMessageType.Vote:
                return(EncodeUtils.HexToByteArray("A1CADD36"));

            default:
                return(new byte[0]);
            }
        }
コード例 #2
0
        public string BuildNewOrder(NewOrder newOrder)
        {
            Wallet.EnsureWalletIsReady();
            NewOrderMessage msgBean = CreateNewOrderMessage(newOrder);

            byte[] msg       = EncodeNewOrderMessage(msgBean);
            byte[] signature = EncodeSignature(Sign(msgBean));
            byte[] stdTx     = EncodeStdTx(msg, signature);
            return(EncodeUtils.ByteArrayToHex(stdTx));
        }
コード例 #3
0
 private byte[] EncodeTokenUnfreezeMessage(TokenUnfreezeMessage tokenUnfreezeMessage)
 {
     proto.TokenUnfreeze tokenUnfreeze = new proto.TokenUnfreeze
     {
         From   = ByteString.CopyFrom(Wallet.DecodeAddress(tokenUnfreezeMessage.From)),
         Amount = tokenUnfreezeMessage.Amount,
         Symbol = tokenUnfreezeMessage.Symbol
     };
     return(EncodeUtils.AminoWrap(tokenUnfreeze.ToByteArray(), MessageType.GetTransactionType(EMessageType.TokenUnfreeze), false));
 }
コード例 #4
0
 private byte[] EncodeCancelOrderMessage(CancelOrderMessage cancelOrderMessage)
 {
     proto.CancelOrder cancelOrder = new proto.CancelOrder
     {
         Sender = ByteString.CopyFrom(Wallet.AddressBytes),
         Symbol = cancelOrderMessage.Symbol,
         Refid  = cancelOrderMessage.RefId
     };
     return(EncodeUtils.AminoWrap(cancelOrder.ToByteArray(), MessageType.GetTransactionType(EMessageType.CancelOrder), false));
 }
コード例 #5
0
 private byte[] EncodeVoteMessage(VoteMessage voteMessage)
 {
     proto.Vote vote = new proto.Vote
     {
         Voter      = ByteString.CopyFrom(Wallet.AddressBytes),
         ProposalId = long.Parse(voteMessage.ProposalId),
         Option     = VoteMessage.ToOption(voteMessage.Option)
     };
     return(EncodeUtils.AminoWrap(vote.ToByteArray(), MessageType.GetTransactionType(EMessageType.Vote), false));
 }
コード例 #6
0
        public string BuildMultiTransfer(MultiTransfer multiTransfer)
        {
            Wallet.EnsureWalletIsReady();
            TransferMessage msgBean = CreateMultiTransferMessage(multiTransfer);

            byte[] msg       = EncodeTransferMessage(msgBean);
            byte[] signature = EncodeSignature(Sign(msgBean));
            byte[] stdTx     = EncodeStdTx(msg, signature);
            return(EncodeUtils.ByteArrayToHex(stdTx));
        }
コード例 #7
0
        public string BuildTokenUnfreeze(TokenUnfreeze tokenUnfreeze)
        {
            Wallet.EnsureWalletIsReady();
            TokenUnfreezeMessage msgBean = CreateTokenUnfreezeMessage(tokenUnfreeze);

            byte[] msg       = EncodeTokenUnfreezeMessage(msgBean);
            byte[] signature = EncodeSignature(Sign(msgBean));
            byte[] stdTx     = EncodeStdTx(msg, signature);
            return(EncodeUtils.ByteArrayToHex(stdTx));
        }
コード例 #8
0
        public string BuildVote(Vote vote)
        {
            Wallet.EnsureWalletIsReady();
            VoteMessage msgBean = CreateVoteMessage(vote);

            byte[] msg       = EncodeVoteMessage(msgBean);
            byte[] signature = EncodeSignature(Sign(msgBean));
            byte[] stdTx     = EncodeStdTx(msg, signature);
            return(EncodeUtils.ByteArrayToHex(stdTx));
        }
コード例 #9
0
        public void WalletTest()
        {
            Wallet wallet = Wallet.FromPrivateKey("95949f757db1f57ca94a5dff23314accbe7abee89597bf6a3c7382c84d7eb832",
                                                  BinanceDexEnvironment.TEST_NET);

            Assert.Equal("tbnb1grpf0955h0ykzq3ar5nmum7y6gdfl6lx8xu7hm", wallet.Address);
            Assert.Equal("40c2979694bbc961023d1d27be6fc4d21a9febe6",
                         EncodeUtils.ByteArrayToHex(wallet.AddressBytes), true);
            Assert.Equal("eb5ae98721026a35920088d98c3888ca68c53dfc93f4564602606cbb87f0fe5ee533db38e502",
                         EncodeUtils.ByteArrayToHex(wallet.PubKeyForSign), true);
        }
コード例 #10
0
        private byte[] EncodeSignature(byte[] signatureBytes)
        {
            proto.StdSignature stdSignature = new proto.StdSignature
            {
                PubKey        = ByteString.CopyFrom(Wallet.PubKeyForSign),
                Signature     = ByteString.CopyFrom(signatureBytes),
                AccountNumber = Wallet.AccountNumber.Value,
                Sequence      = Wallet.Sequence.Value
            };

            return(EncodeUtils.AminoWrap(stdSignature.ToByteArray(), MessageType.GetTransactionType(EMessageType.StdSignature), false));
        }
コード例 #11
0
 private byte[] EncodeStdTx(byte[] msg, byte[] signature)
 {
     proto.StdTx stdTx = new proto.StdTx();
     stdTx.Msgs.Add(ByteString.CopyFrom(msg));
     stdTx.Signatures.Add(ByteString.CopyFrom(signature));
     stdTx.Memo   = TranscationOption.Memo;
     stdTx.Source = TranscationOption.Source;
     if (TranscationOption.Data != null)
     {
         stdTx.Data = ByteString.CopyFrom(TranscationOption.Data);
     }
     return(EncodeUtils.AminoWrap(stdTx.ToByteArray(), MessageType.GetTransactionType(EMessageType.StdTx), true));
 }
コード例 #12
0
 private byte[] EncodeTransferMessage(TransferMessage transferMessage)
 {
     proto.Send send = new proto.Send();
     foreach (InputOutput input in transferMessage.Inputs)
     {
         send.Inputs.Add(toProtoInput(input));
     }
     foreach (InputOutput output in transferMessage.Outputs)
     {
         send.Outputs.Add(toProtoOutput(output));
     }
     return(EncodeUtils.AminoWrap(send.ToByteArray(), MessageType.GetTransactionType(EMessageType.Send), false));
 }
コード例 #13
0
 private byte[] EncodeNewOrderMessage(NewOrderMessage newOrderMessage)
 {
     proto.NewOrder newOrder = new proto.NewOrder
     {
         Sender      = ByteString.CopyFrom(Wallet.AddressBytes),
         Id          = newOrderMessage.Id,
         Symbol      = newOrderMessage.Symbol,
         Ordertype   = newOrderMessage.OrderType,
         Side        = newOrderMessage.Side,
         Price       = newOrderMessage.Price,
         Quantity    = newOrderMessage.Quantity,
         Timeinforce = newOrderMessage.TimeInForce
     };
     return(EncodeUtils.AminoWrap(newOrder.ToByteArray(), MessageType.GetTransactionType(EMessageType.NewOrder), false));
 }
コード例 #14
0
 private String GenerateOrderId()
 {
     return(EncodeUtils.ByteArrayToHex(Wallet.AddressBytes).ToUpper() + "-" + (Wallet.Sequence + 1));
 }
コード例 #15
0
 public byte[] EncodeMessage <T>(T message, byte[] prefix) where T : class
 {
     return(EncodeUtils.AminoWrap(this.ProtoSerialize <T>(message), prefix, false));
 }
コード例 #16
0
 public string BytesToHex(byte[] bytes)
 {
     return(EncodeUtils.BytesToHex(bytes));
 }