-
Notifications
You must be signed in to change notification settings - Fork 213
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
Transaction API Handler #182
Conversation
seems a bit broader than what #93 aimed at - but that's minor |
Well, depends how you interpret the acceptance criteria "The API must support creation of transactions according to the API Swagger specification https://raw.githubusercontent.com/input-output-hk/cardano-wallet/master/specifications/api/swagger.yaml" :/ |
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.
Looks good so far, few minor points
src/Cardano/Wallet.hs
Outdated
|
||
, signTx = \wid creds (CoinSelection ins outs chgs) -> DB.withLock db $ do | ||
withExceptT ErrSubmitTxNetwork $ postTx network signed | ||
let amt = fromIntegral $ sum (getCoin . coin <$> tx ^. #outputs) |
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.
hm, in this case amount will always be equal to sum of all input accounts, as this counts in also change amount. Is it expected from clients that TxMeta.amount
includes change 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.
Ah! Good point. Will correct this.
@@ -360,8 +407,8 @@ mkWalletLayer db network = WalletLayer | |||
-> ExceptT ErrNoSuchWallet IO () | |||
restoreBlocks wid blocks tip = do | |||
let (inf, sup) = | |||
( slotId . header . head $ blocks | |||
, slotId . header . last $ blocks | |||
( view #slotId . header . head $ blocks |
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.
is there a real need to use lens sintax here?
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.
Unfortunately yes, because we have conflicting record names. I am not quite satisfied with that, mostly because we don't use lens consistently at the moment. So, it feels really ad-hoc ine some cases.
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.
aha I see - I didn't notice name conflict. In that case it looks sensible (not ideal - but still very clear to the reader)
@@ -150,7 +152,7 @@ data PostTransactionData = PostTransactionData | |||
, passphrase :: !(ApiT (Passphrase "encryption")) | |||
} deriving (Eq, Generic, Show) | |||
|
|||
data ApiTransaction = Transaction | |||
data ApiTransaction = ApiTransaction |
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.
:/ nice catch
parseJSON bytes = do | ||
v@(ApiCoins _ (Quantity c)) <- | ||
genericParseJSON defaultRecordTypeOptions bytes | ||
if isValidCoin (Coin $ fromIntegral c) |
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.
👍
src/Cardano/Wallet/Api/Types.hs
Outdated
if isValidCoin (Coin $ fromIntegral c) | ||
then return v | ||
else fail $ | ||
"invalid coin value: value has to be lower than" |
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.
"lower than or equal"
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.
Fun fact: In English, "lower than" (or similarly, "higher than") have the same meaning as <
and, we therefore require "lower than or equal" to mean <=
.
In French, the literal translation for "lower than" would be "inférieur à", which in Maths, is interpreted as <=
, and French would say "strictement inférieur à" to mean <
(which would translate to "strictly lower than").
Anyway, Good catch 😅
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.
Interesting!
For this example, Croatian follows the same natural language rules as English does (probably that's the reason why it was easier to spot it for me - and easier to do the mistake for you). Interesting how we tend to think/solve-problems in our natural language constrains
:: Tx | ||
-> Wallet s | ||
-> Wallet s | ||
newPending !tx (Wallet !utxo !pending !history !tip !s) = |
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.
maybe dumb question: is there a reason strict annotation is really necessary here? (I don't usually use this until I am really sure this will create lots of unnecessary thunks - but I haven't looked at the code to figure out is this so)
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.
On newPending
it's more debatable. It's definitely necessary on the applyBlock
to avoid constructing too many chunks (as we generally apply a whole epoch before evaluating the state again). On new pending, we evaluate it right away by storing it to disk.
I didn't thought this was part of this task but I see it can be if "must support" means "API must support fully working implementation" and not "API must have endpoint" that I thought it means. My bad |
d6cddec
to
2484bf1
Compare
2484bf1
to
62a26d2
Compare
Well, requirements can be clearer too ;) ... Hence the need for discussing and reviewing them. |
20478d3
to
513448d
Compare
513448d
to
1ad8083
Compare
1ad8083
to
6d09535
Compare
@akegalj May you have a second look at this ? |
I will have a second look immediatelly |
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.
LGTM
{ status = Pending | ||
, direction = Outgoing | ||
, slotId = currentTip w | ||
, amount = Quantity (amtInps - amtChng) |
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.
yes - I think this is what we are aiming for
Issue Number
#93
Overview
Comments
Haven't tested anything yet, still waiting for a few things regarding the transaction signing testing first.
master