예제 #1
0
        public PathElement(JsonElement json)
        {
            JsonElement element;

            if (json.TryGetProperty("account", out element))
            {
                Account = new AccountId(element.GetString());
            }
            else
            {
                Account = default;
            }
            if (json.TryGetProperty("currency", out element))
            {
                Currency = new CurrencyCode(element.GetString());
            }
            else
            {
                Currency = default;
            }
            if (json.TryGetProperty("issuer", out element))
            {
                Issuer = new AccountId(element.GetString());
            }
            else
            {
                Issuer = default;
            }
        }
예제 #2
0
파일: Domain.cs 프로젝트: Ibasa/Ripple
 public CurrencyType(AccountId issuer, CurrencyCode currencyCode)
 {
     if (currencyCode == CurrencyCode.XRP)
     {
         throw new ArgumentException("Can not be XRP", "currencyCode");
     }
     CurrencyCode = currencyCode;
     Issuer       = issuer;
 }
예제 #3
0
        public static Hash256 CalculateId(AccountId low, AccountId high, CurrencyCode currencyCode)
        {
            Span <byte> buffer = stackalloc byte[62];

            System.Buffers.Binary.BinaryPrimitives.WriteUInt16BigEndian(buffer, 0x0072);
            low.CopyTo(buffer.Slice(2));
            high.CopyTo(buffer.Slice(22));
            currencyCode.CopyTo(buffer.Slice(42));
            return(CalculateId(buffer));
        }
예제 #4
0
파일: Domain.cs 프로젝트: Ibasa/Ripple
 public Amount(AccountId issuer, CurrencyCode currencyCode, Currency value)
 {
     if (currencyCode == CurrencyCode.XRP)
     {
         throw new ArgumentException("Can not be XRP", "currencyCode");
     }
     this.value        = Currency.ToUInt64Bits(value);
     this.currencyCode = currencyCode;
     this.issuer       = issuer;
 }
예제 #5
0
파일: Domain.cs 프로젝트: Ibasa/Ripple
        public IssuedAmount(AccountId issuer, CurrencyCode currencyCode, Currency value)
        {
            if (currencyCode == CurrencyCode.XRP)
            {
                throw new ArgumentException("Can not be XRP", "currencyCode");
            }

            Issuer       = issuer;
            CurrencyCode = currencyCode;
            Value        = value;
        }
예제 #6
0
파일: Domain.cs 프로젝트: Ibasa/Ripple
 public Amount(ulong drops)
 {
     if (drops > 100000000000000000)
     {
         throw new ArgumentOutOfRangeException("drops", drops, "drops must be less than or equal to 100,000,000,000,000,000");
     }
     this.value = drops | 0x4000_0000_0000_0000;
     // These fields are only used for IssuedAmount but struct constructor has to set all fields.
     this.currencyCode = default;
     this.issuer       = default;
 }
예제 #7
0
파일: Domain.cs 프로젝트: Ibasa/Ripple
        internal static CurrencyType ReadJson(JsonElement json)
        {
            var currencyCode = new CurrencyCode(json.GetProperty("currency").GetString());

            if (json.TryGetProperty("issuer", out var element))
            {
                return(new CurrencyType(new AccountId(element.GetString()), currencyCode));
            }
            else
            {
                return(new CurrencyType(currencyCode));
            }
        }
예제 #8
0
        public static Hash256 CalculateOfferId(CurrencyCode takerPaysCurrency, CurrencyCode takerGetsCurrency, AccountId takerPaysIssuer, AccountId takerGetsIssuer, ulong offers)
        {
            // The first page of an Offer Directory has a special ID: the higher 192 bits define the order book, and the remaining 64 bits define the exchange rate of the offers in that directory.
            // (The ID is big-endian, so the book is in the more significant bits, which come first, and the quality is in the less significant bits which come last.)
            // This provides a way to iterate through an order book from best offers to worst.Specifically: the first 192 bits are the first 192 bits of the SHA-512Half of the following values, concatenated in order:
            //
            //The Book Directory space key(0x0042)
            //The 160-bit currency code from the TakerPaysCurrency
            //The 160-bit currency code from the TakerGetsCurrency
            //The AccountID from the TakerPaysIssuer
            //The AccountID from the TakerGetsIssuer
            //The lower 64 bits of an Offer Directory's ID represent the TakerPays amount divided by TakerGets amount from the offer(s) in that directory as a 64-bit number in the XRP Ledger's internal amount format.
            //
            Span <byte> buffer = stackalloc byte[38];

            System.Buffers.Binary.BinaryPrimitives.WriteUInt16BigEndian(buffer, 0x0042);
            takerPaysCurrency.CopyTo(buffer.Slice(2));
            takerGetsCurrency.CopyTo(buffer.Slice(22));
            takerPaysIssuer.CopyTo(buffer.Slice(42));
            takerGetsIssuer.CopyTo(buffer.Slice(62));
            Hash256 hash = CalculateId(buffer);

            return(hash);
        }
예제 #9
0
 public static PathElement FromIssuedCurrency(AccountId issuer, CurrencyCode currency)
 {
     return(new PathElement(null, currency, issuer));
 }
예제 #10
0
 public static PathElement FromCurrency(CurrencyCode currency)
 {
     return(new PathElement(null, currency, null));
 }
예제 #11
0
파일: Domain.cs 프로젝트: Ibasa/Ripple
 public CurrencyType(CurrencyCode currencyCode)
 {
     CurrencyCode = currencyCode;
     Issuer       = null;
 }