-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Payment api v2 #1468
Payment api v2 #1468
Conversation
Stream &operator>>(Stream &stream, Compact<N> &compact) { | ||
scale::CompactInteger n; | ||
stream >> n; | ||
compact.number = n.convert_to<N>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it truncate or throw (e.g. 0x1_00u16 -> u8
or -1 -> u8
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made alias types for boost multiprecision numbers checked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiprecision and standard integers behave differently.
(-1).convert_to<AnyUnsignedType> // good, std::range_error
(1 << 128).convert_to<u128> // good, std::range_error
(1 << 8).convert_to<u8> // bad, truncated
core/scale/big_fixed_integers.hpp
Outdated
for (size_t i = 0; i < BigIntegerTraits<N>::BIT_SIZE; i += 8) { | ||
fixed.number |= N(stream.nextByte()) << i; | ||
} | ||
return stream; | ||
} | ||
|
||
template <typename Stream, | ||
typename N, | ||
typename = std::enable_if_t<Stream::is_encoder_stream>, | ||
typename = std::enable_if_t<BigIntegerTraits<N>::value>> | ||
Stream &operator<<(Stream &stream, EncodeAsFixed<N> fixed) { | ||
constexpr size_t bits = BigIntegerTraits<N>::BIT_SIZE; | ||
for (N i = 0; i < bits; i += 8) { | ||
stream << fixed & 0xFF; | ||
fixed >>= 8; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are export_bits
and import_bits
functions.
Example of custom output iterator.
Maybe remove BIT_SIZE
if it's not used elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation was rather unclear about the exact format the bits are imported in (but in practice it's the correct lsb order) so I avoided it. However now these functions are used for all kinds of integers, not just from boost multiprecision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They accept chunk_bit_width
and bool lsb_or_msb
.
BigIntegerTraits
is only implemented for multiprecision types.
Standard integers are already encoded as fixed.
Referenced issues
resolves #1449
Description of the Change
It is worth noticing that version 2 is actually not yet used in Polkadot and Rococo, so it was not tested on a living network.
Benefits
Possible Drawbacks