-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
chore: renamed plus and minus to add and subtract, added utility methods #457
base: master
Are you sure you want to change the base?
chore: renamed plus and minus to add and subtract, added utility methods #457
Conversation
* Add support for Optional types in blueprint processing Implemented changes to handle Optional types in blueprint definitions. Added tests for processing blueprints with basic option types and ensured proper compilation. Updated schema and processing utilities to accommodate new Optional type handling. * Add Pair type support and serialization logic Added the Pair type to Type and JavaType enums. Updated BlueprintSchema, ConverterCodeGenerator, and ClassDefinitionGenerator to handle Pair serialization and deserialization. Introduced unit tests to verify Pair functionality. * Fix package issue due to aiken stdlib definitions * To fix #452 Add tests for ScheduledTransactionRedeemer model and related tests
Refactor `COSESignBuilder` and `COSESign1Builder` to handle external payloads and add support for payload hashing. Update `CIP30DataSigner` logic to remove redundant hashed payload header. Adjust tests to align with these changes and add new test files for Rust code comparisons.
Refactor COSESign builders for external payload and hashing
feat: support for CIP-30 payload hash with an extra overloaded methods
} | ||
|
||
|
||
public static Value from(String policyId, String assetName, BigInteger amount) { |
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.
@nemo83 Thanks for the PR.
from(policyId, assetName, amount)
fromLovelace(amount)
If I am not wrong, in the case of lovelace, the policy ID is empty. But, I need to verify that. To avoid confusion, as these values are represented differently in the Value structure, we can keep #1 for native assets and #2 for lovelace. For #1, we can add a null check for policy id. Null check for asset name is not required as it could be empty.
Also, we can add an overloaded method
addLovelace(amount)
.
And in Value add(String unit, BigInteger amount)
, check
- if
unit=lovelace
then addLovelace(amount) - else
add(from(...)
(current code)
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.
Thanks for the review.
For lovelace values, both policy id and asset name should be empty byte array.
The class Amount
in CCL has just unit
attribute which is set to lovelace
for ada amount, which confused me in the past coz when doing substring, it would then be policyId = lovelace. The Amt
class in yaci has policyId empty and asset name equals to lovelace.
IMHO, both should be empty, setting either of them or unit to lovelace just complicates things. Hence the policy check and asset name check.
Will leverage AssetUtil
to try to simplify and add the other add
methods
|
||
private Tuple<String, String> getPolicyAndAssetName(String unit) { | ||
String sanitisedUnit = unit.replace(".", ""); | ||
String policyId = sanitisedUnit.substring(0, 56); |
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.
You may want to use AssetUtil
here.
public boolean isPositive() { | ||
boolean isCoinPositive = coin.longValue() >= 0; | ||
boolean allAssetsPositive = multiAssets == null || multiAssets.isEmpty() || | ||
multiAssets.stream().allMatch(multiAsset -> multiAsset.getAssets().stream().allMatch(asset -> asset.getValue().longValue() >= 0)); |
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.
Can we change the long >= 0 to compare BigInteger ?
@nemo83 Thanks. A Few Comments:
Hope it makes sense, and I didn't miss anything. |
multiAsset.getAssets().removeIf(asset -> BigInteger.ZERO.equals(asset.getValue()))); | ||
//Remove multiasset if there's no asset | ||
difMultiAssets.removeIf(multiAsset -> multiAsset.getAssets() == null || multiAsset.getAssets().isEmpty()); | ||
List<MultiAsset> filteredMultiAssets = difMultiAssets |
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.
This change is removing forEach and using stream api to avoid extra iteration. right?
Quality Gate failedFailed conditions |
In recent days I had to do a lot of comparisons, addition and subtractions of ada and native assets. To support this I've created local utility classes for Value and Amount in CCL, Amt in yaci and I'm sure I'm missing something somewhere else.
While the different models in different libraries can be somehow justified, I think CCL currently lack a powerful and versatile
Value
object that allows basic operations for the most common types.In this PR I have:
plus
andminus
in favour to the more widely adopted and correctadd
andsubtract
unit
and the couplepolicyId
assetName
isZero
methodisPositive
methodamountOf
forunit
and the couplepolicyId
assetName
The one thing that I really don't like is the fact we have to remember to prepend "0x" to asset name if we are passing as hex, which should be really the only, default, case.