-
Notifications
You must be signed in to change notification settings - Fork 220
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
ADP-494 - Add POST endpoint for script address #2253
Conversation
specifications/api/swagger.yaml
Outdated
@@ -610,6 +640,16 @@ x-signedTransactionBlob: &signedTransactionBlob | |||
type: string | |||
format: binary | |||
|
|||
x-addressParts: &addressParts |
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.
enterprise address -> { networkTag, paymentCredential }
reward account address -> { networkTag, stakeCredential }
stake address -> { networkTag, paymentCredential, stakeCredential }
specifications/api/swagger.yaml
Outdated
x-networkTag: &networkTag | ||
description: Can be null for 'Icarus' and 'Byron' styles. | ||
type: integer | ||
minimum: 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.
This should not be necessary because the server is already instantiated for one of the given networks. So the network tag is implicit based on how one started the server (--mainnet
or --testnet
)
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.
removed in ccd4eb4
specifications/api/swagger.yaml
Outdated
@@ -321,6 +326,30 @@ x-poolMetadataSource: &poolMetadataSource | |||
format: uri | |||
example: https://smash.cardano-mainnet.iohk.io/ | |||
|
|||
x-walletCredentialPubkey: &walletCredentialPubkey | |||
description: An extended public key (public key + chain code) for credential |
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.
Why require an extended key here? The chain code is unnecessary.
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.
to my best knowledge we are hashing extended public key with blake2b not just public key -> https://github.com/input-output-hk/cardano-addresses/blob/master/core/lib/Cardano/Address/Style/Shelley.hs#L639
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.
No we're not :)
xpubPublicKey
is the public key, without chain 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.
indeed! Thanks! I made this mistake mainly because of this :
$ cat signingKey1.prv | cardano-address key public --bech32
xpub13pfp60uf4ru7cmj5d57xjdzj6lagn328ah67h35urqrl92jn094z0s07fcy2pvfw3xfhna6fa24na8nk6lraymjcrl5wwj6chsjqtjqlfw44z
So we will need a way to get public key only (not chain code included) in cardano-addresses, right?
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.
I think that'd be an interesting feature indeed. Be able to get just the public part, without chain 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.
Alternatively, we can have the API accepts both, but the chain code should not a required
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.
corrected in 2f91803
specifications/api/swagger.yaml
Outdated
x-walletCredentialPubkey: &walletCredentialPubkey | ||
description: An extended public key (public key + chain code) for credential | ||
type: string | ||
format: hex |
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.
What about bech32 ;) ?
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.
used xpub
hrp -> ccd4eb4
|
||
x-walletScript: &walletScript | ||
description: A script as text with predicates and verification keys. Here probably we should add a full-fledged script object | ||
type: string |
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.
How is that a string
🤔 ? Isn't the goal here to re-use the JSON object instances from cardano-addresses?
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.
it is going to be json object. just doing this in steps
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.
my attempt -> ccd4eb4
But when
$ openapi-spec-validator --schema 3.0.0 specifications/api/swagger.yaml
found undefined alias 'walletCredentialScript'
in "<file>", line 357, column 14
need to recall how to sneak recursive scheme in swagger
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.
Look at transaction metadatum. I recall we did something similar.
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, now it seems to be ok -> 2f91803
ccd4eb4
to
2f91803
Compare
12777ed
to
a3ed826
Compare
stack.yaml
Outdated
@@ -87,177 +87,177 @@ nix: | |||
# package cardano-crypto | |||
# tests: False | |||
# benchmarks: False | |||
# | |||
# |
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.
I think that stack2cabal relies on these whitespaces and they shouldn't be trimmed.
@paweljakubas, is your editor correctly picking up the config from: https://github.com/input-output-hk/cardano-wallet/blob/master/.editorconfig#L11-L12
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.
it seems so - this is config that is taken by my editor for this file:
# EditorConfig for /home/pawel/Work/IOHK/cardano-wallet/stack.yaml
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = true
tab_width = 2
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.
I think trim_trailling_whitespace=true
is a nice thing to have.
When auto-generated whitespace gets removed in a file that you edited, use your editor's git function to discard those irrelevant hunks.
@@ -46,7 +46,7 @@ extra-deps: | |||
|
|||
# cardano-addresses-2.1.0 | |||
- git: https://github.com/input-output-hk/cardano-addresses | |||
commit: e0ab4587266430a08734e1aec1c29d261a9a3b70 | |||
commit: 1399751501b03346265b2e429e5832bacd6df279 |
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.
We should only pick released version of cardano-addresses. But I am quite reluctant releasing it in the state it is right now :/ ... I'd rather have it compliant with CIP5 for the release.
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.
agree, pasted it as it is just in order to have a way to interact with what we have in cardano-addresses
07e4047
to
6b90e68
Compare
netTag = case testEquality (typeRep @n) (typeRep @'Mainnet) of | ||
Just{} -> 1 | ||
Nothing -> 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.
This one is escaping me -> I want n -> Int ... for now I hacked it to be 1 (Mainnet) to carry on with integration tests
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.
Note that this should not be in core
, because it only concerns cardano-node and really is cardano-node specific. Plus, you should be able to simply re-use: https://github.com/input-output-hk/cardano-wallet/blob/368b9fc27249e1faf6577c020297b74d4cf6f161/lib/shelley/src/Cardano/Wallet/Shelley.hs#L203-L218
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 this hint. did it in 3cf22f4 also did some reshuffling of code connected with HasNetworkId to use it
{ payload :: ByteString | ||
, flavour :: AnyAddressType | ||
, network :: Int | ||
} deriving (Eq, Generic, Show) |
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.
Why not re-use the existing types for Addresses ?
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.
If I use Addresses I will be able to differentiate between addr
and addr_test
based on network. but I will not be able to use reward_account's stake
and stake_test
(to my best knowledge). This was main reason I introduced this type
} deriving (Eq, Generic, Show) | ||
|
||
data Credential = Credential | ||
{ credential :: Either ApiPubKey ApiScript |
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.
May I suggest a sum-type instead of wrapping a Either
?
data Credential
= CredentialPubKey ...
| CredentialScript
?
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 be called ApiCredential as well for consistency?
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.
done in 1cdaf25
pure ( unAddress $ | ||
CA.delegationAddress discriminant (spendingFromScript script1) (stakingFromScript script2) | ||
, EnterpriseDelegating ) | ||
(Nothing, Nothing) -> fail "At least one credential is required" |
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.
That's one big chunk 😬
My recommendation would be to capture this already in the API data-type itself. So, instead of:
data ApiCredentials = ApiCredentials
{ spending :: !(Maybe Credential)
, staking :: !(Maybe Credential)
} deriving (Eq, Generic, Show)
have something along the lines of:
data ApiAddressData
= AddrBase Credential Credential
| AddrPtr Credential Ptr
| AddrEnterprise Credential
| AddrBootstrap Address
this would be quite more readable and also get rid of the "impossible" case.
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.
good idea, indeed it made things simpler -> 1071e78
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.
Good start 👍
specifications/api/swagger.yaml
Outdated
- any condition for which any list element' expectation is to be met for the condition to be valid | ||
- some condition for which a minimal number of list elements' expectation is to be met for the condition to be valid | ||
example: | ||
0: "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt36ms" |
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 value should be a yaml list of examples, rather than an object with numeric keys. The single example object is specific to Metadata.
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.
done in e6c0510
properties: | ||
address: *anyAddress | ||
|
||
ApiCredential: &ApiCredential |
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.
Could this be renamed to ScriptAddressCredential
? Are the Api
prefixes needed for anything? This is a swagger file - it's all API.
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.
@rvl we typically keep the same naming as in the Cardano.Wallet.Api.Types
module for the swagger file references because it creates a straightforward mapping for the automated schema validations we perform in tests. This way, one can write ToSchema
instances as:
instance ToSchema (ApiSelectCoinsPayments n) where
declareNamedSchema _ = declareSchemaForDefinition "ApiSelectCoinsPayments"
instance ToSchema ApiSelectCoinsAction where
declareNamedSchema _ = declareSchemaForDefinition "ApiSelectCoinsAction"
instance ToSchema (ApiCoinSelection n) where
declareNamedSchema _ = declareSchemaForDefinition "ApiCoinSelection"
instance ToSchema ApiWallet where
declareNamedSchema _ = declareSchemaForDefinition "ApiWallet"
instance ToSchema ApiByronWallet where
declareNamedSchema _ = declareSchemaForDefinition "ApiByronWallet"
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.
We could even push it further and have default instances relying on generics and Typeable.
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 ok thanks.
specifications/api/swagger.yaml
Outdated
ApiScript: &ApiScript | ||
type: object | ||
required: | ||
- script | ||
properties: | ||
script: *script | ||
|
||
ApiPubKey: &ApiPubKey | ||
type: object | ||
required: | ||
- pub_key | ||
properties: | ||
pub_key: *credentialPubKey |
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.
I think these could both be removed and embedded directly into CredentialValue
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.
I wanted them to be exposed to have a way in TypeSpec to check
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.
OK fair enough
@@ -384,6 +398,34 @@ data ApiAddress (n :: NetworkDiscriminant) = ApiAddress | |||
, state :: !(ApiT AddressState) | |||
} deriving (Eq, Generic, Show) | |||
|
|||
newtype ApiScript = ApiScript | |||
{ script :: ApiT Script |
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.
I think if the sole field is going to be ApiT Script
, then you don't need the ApiScript
newtype.
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.
Perhaps the newtype might be needed if you want automatic JSON instances, but it looks like they are non-generically defined below.
} deriving (Eq, Generic, Show) | ||
|
||
data Credential = Credential | ||
{ credential :: Either ApiPubKey ApiScript |
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 be called ApiCredential as well for consistency?
arbitrary = ApiScript . ApiT <$> arbitrary | ||
|
||
instance Arbitrary Script where | ||
arbitrary = do |
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.
Same comment about generators of arbitrary tree structures applies here as it did in cardano-addresses.
In fact, could the types and generators from cardano-addresses be re-used?
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.
did in e6c0510
stack.yaml
Outdated
@@ -87,177 +87,177 @@ nix: | |||
# package cardano-crypto | |||
# tests: False | |||
# benchmarks: False | |||
# | |||
# |
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.
I think trim_trailling_whitespace=true
is a nice thing to have.
When auto-generated whitespace gets removed in a file that you edited, use your editor's git function to discard those irrelevant hunks.
postAnyAddress | ||
:: forall n. ApiCredentials | ||
-> Handler AnyAddress | ||
postAnyAddress body = do |
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.
It looks like not just any address can be posted. Is that right?
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 can construct enterprise, reward account and base address for any credential (either from key or script). There is also pointer address missing that could be added in forthcoming PR. That's the rationale I proposed the name AnyAddress
2123387
to
1cdaf25
Compare
e6c0510
to
6459319
Compare
-- Generating golden test data for enterprise addresses: | ||
--- $ cardano-address script hash "$(cat script.txt)" \ | ||
--- | cardano-address address payment --from-script --network-tag mainnet | ||
it "ANY_ADDRESS_POST_01 - Golden tests for enterprise script address - signature" $ \ctx -> do |
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.
Nitpicking but why golden? Afaik, golden are unit tests with output in separate file which is not the case 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.
golden because I have generated golden data in cardano-address for all examples, and check if all json/handling/.. machinery comes to the same results
specifications/api/swagger.yaml
Outdated
, "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt38ms"] | ||
, "at_least" : 2 | ||
} | ||
} ] } |
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 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, will fix
I added golden for enterprise, reward account and base with script(s) as credential. I will add more (probably in separate PR) containing public key in credential and mixed after I will add Plus I have problem with this trimming - cannot revert it |
ApiScript correct stack.yaml stack.yaml Regenerate nix better Malformed
refine types make unit tests pass finally
add AnyAddress to swagger and and core unit tests fixup! Regenerate nix
…there plus code reshuffling
fix malformed and change heap size regenerate ApiAddressData some swagger fixes and reuse of Script Arbitrary instance from cardano-addresses hlint
git checkout master -- stack.yaml git reset -p (use that to unstage the first hunk) git commit git checkout -- stack.yaml
final polishing Clean up Api.Types aeson instances 201 -> 202 status code plus staking -> stake, spending -> payment in ApiAddressData HLint
435400b
to
cf40f51
Compare
bors r+ |
Build succeeded: |
Issue Number
https://jira.iohk.io/browse/ADP-494
Overview
Comments