public void DecodeDoesntThrowWhenFormatIsIncorrect()
 {
     Assert.False(InterFluxOpReturnEncoder.TryDecode("INTER_3_345345", out int _, out string _));
     Assert.False(InterFluxOpReturnEncoder.TryDecode("INTER3_", out int _, out string _));
     Assert.False(InterFluxOpReturnEncoder.TryDecode("INTERefsdvsdvdsvsdv", out int _, out string _));
     Assert.False(InterFluxOpReturnEncoder.TryDecode("xvev456545cwsdfFSXVB365", out int _, out string _));
 }
Example #2
0
        public void EncodeAndDecodeETHAddressLegacy_Pass()
        {
            bool result = InterFluxOpReturnEncoder.TryDecode("0xd2390da742872294BE05dc7359D7249d7C79460E", out int resultChain, out string resultAddress);

            Assert.True(result);
            Assert.Equal(DestinationChain.ETH, (DestinationChain)resultChain);
            Assert.Equal("0xd2390da742872294BE05dc7359D7249d7C79460E", resultAddress);
        }
        public void EncodeAndDecodeETHAddress()
        {
            string address = "0xd2390da742872294BE05dc7359D7249d7C79460E";
            string encoded = InterFluxOpReturnEncoder.Encode(DestinationChain.ETH, address);
            bool   success = InterFluxOpReturnEncoder.TryDecode(encoded, out int resultChain, out string resultAddress);

            Assert.True(success);
            Assert.Equal(DestinationChain.ETH, (DestinationChain)resultChain);
            Assert.Equal(address, resultAddress);
        }
Example #4
0
        /// <inheritdoc />
        public IDeposit ExtractDepositFromTransaction(Transaction transaction, int blockHeight, uint256 blockHash)
        {
            // Coinbase transactions can't have deposits.
            if (transaction.IsCoinBase)
            {
                return(null);
            }

            // Deposits have a certain structure.
            if (transaction.Outputs.Count != ExpectedNumberOfOutputsNoChange && transaction.Outputs.Count != ExpectedNumberOfOutputsChange)
            {
                return(null);
            }

            var depositsToMultisig = transaction.Outputs.Where(output =>
                                                               output.ScriptPubKey == this.depositScript &&
                                                               output.Value >= FederatedPegSettings.CrossChainTransferMinimum).ToList();

            if (!depositsToMultisig.Any())
            {
                return(null);
            }

            // Check the common case first.
            bool             conversionTransaction = false;
            DestinationChain targetChain           = DestinationChain.STRAX;

            if (!this.opReturnDataReader.TryGetTargetAddress(transaction, out string targetAddress))
            {
                byte[] opReturnBytes = OpReturnDataReader.SelectBytesContentFromOpReturn(transaction).FirstOrDefault();

                if (opReturnBytes != null && InterFluxOpReturnEncoder.TryDecode(opReturnBytes, out int destinationChain, out targetAddress))
                {
                    targetChain = (DestinationChain)destinationChain;
                }
                else
                {
                    return(null);
                }

                conversionTransaction = true;
            }
        public void CanEncodeAndDecode()
        {
            int    chain   = 3;
            string address = "0x51EC92A3aB8cfcA412Ea43766A9259523fC81501";

            string encoded = InterFluxOpReturnEncoder.Encode(chain, address);

            bool success = InterFluxOpReturnEncoder.TryDecode(encoded, out int resultChain, out string resultAddress);

            Assert.True(success);
            Assert.Equal(chain, resultChain);
            Assert.Equal(address, resultAddress);


            byte[] encodedBytes = Encoding.UTF8.GetBytes(encoded);
            bool   success2     = InterFluxOpReturnEncoder.TryDecode(encodedBytes, out int resultChain2, out string resultAddress2);

            Assert.True(success2);
            Assert.Equal(chain, resultChain2);
            Assert.Equal(address, resultAddress2);
        }
Example #6
0
        public void EncodeAndDecodeETHAddressLegacy_Fail()
        {
            bool result = InterFluxOpReturnEncoder.TryDecode("0xd2390da742872294BE05dc7359D7249d7C9460E", out int resultChain, out string resultAddress);

            Assert.False(result);
        }