Skip to content
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

Merged
merged 3 commits into from
Apr 26, 2019
Merged

Transaction API Handler #182

merged 3 commits into from
Apr 26, 2019

Conversation

KtorZ
Copy link
Member

@KtorZ KtorZ commented Apr 25, 2019

Issue Number

#93

Overview

  • I have implemented the API handler to construct, sign and submit transactions
  • I have computed, stored and returned corresponding transaction metadata

Comments

Haven't tested anything yet, still waiting for a few things regarding the transaction signing testing first.

⚠️ Base Branch Isn't master ⚠️

@KtorZ KtorZ requested a review from akegalj April 25, 2019 13:49
@KtorZ KtorZ self-assigned this Apr 25, 2019
@akegalj
Copy link
Contributor

akegalj commented Apr 25, 2019

seems a bit broader than what #93 aimed at - but that's minor

@KtorZ
Copy link
Member Author

KtorZ commented Apr 25, 2019

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"

:/

Copy link
Contributor

@akegalj akegalj left a 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


, signTx = \wid creds (CoinSelection ins outs chgs) -> DB.withLock db $ do
withExceptT ErrSubmitTxNetwork $ postTx network signed
let amt = fromIntegral $ sum (getCoin . coin <$> tx ^. #outputs)
Copy link
Contributor

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?

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

@akegalj akegalj Apr 26, 2019

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
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if isValidCoin (Coin $ fromIntegral c)
then return v
else fail $
"invalid coin value: value has to be lower than"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"lower than or equal"

Copy link
Member Author

@KtorZ KtorZ Apr 26, 2019

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 😅

Copy link
Contributor

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) =
Copy link
Contributor

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)

Copy link
Member Author

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.

@akegalj
Copy link
Contributor

akegalj commented Apr 25, 2019

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"

:/

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

@KtorZ
Copy link
Member Author

KtorZ commented Apr 26, 2019

@akegalj: "My bad"

Well, requirements can be clearer too ;) ... Hence the need for discussing and reviewing them.

@KtorZ KtorZ force-pushed the KtorZ/93/transaction-api-handler branch from 20478d3 to 513448d Compare April 26, 2019 10:59
@KtorZ KtorZ changed the base branch from KtorZ/95/keystore-in-db to master April 26, 2019 10:59
@KtorZ KtorZ force-pushed the KtorZ/93/transaction-api-handler branch from 513448d to 1ad8083 Compare April 26, 2019 11:10
@KtorZ KtorZ force-pushed the KtorZ/93/transaction-api-handler branch from 1ad8083 to 6d09535 Compare April 26, 2019 12:03
@KtorZ
Copy link
Member Author

KtorZ commented Apr 26, 2019

@akegalj May you have a second look at this ?

@akegalj
Copy link
Contributor

akegalj commented Apr 26, 2019

@akegalj May you have a second look at this ?

I will have a second look immediatelly

Copy link
Contributor

@akegalj akegalj left a 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)
Copy link
Contributor

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

@KtorZ KtorZ merged commit 598b911 into master Apr 26, 2019
@KtorZ KtorZ deleted the KtorZ/93/transaction-api-handler branch April 26, 2019 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants