-
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
Add postSignedTx
to HttpBridge
#130
Conversation
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
fe4769d
to
eb58cda
Compare
src/Cardano/Wallet/Binary.hs
Outdated
<> mconcat (map encodeOne list) | ||
|
||
sign :: Tx -> [Witness] -> SignedTx | ||
sign tx witnesses = signedTxFromBS . toBS $ encodeSignedTx (tx, witnesses) |
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.
Unsure about the location of this function as well as SignedTx
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.
For lack of a better place, I think they're fine here for now. Though here I think the name is misleading. I'd expect a "sign" function to produce the actual witnesses for a given address. Here, it's really just composing things together.
(as mentioned in another comment, I don't think there's any need for that at this stage and encodeSignedTx
is enough on its own).
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 currently removed) but I don't like polluting the integration tests with imports to CBOR
and BL
+ and forced to add cborg
as dependency.
I do think/suspect something with the signature :: Tx -> [Witness] -> SignedTx
should exist.
cborRoundtrip decode encode a = do | ||
let bytes = CBOR.toLazyByteString $ encode a | ||
let a' = unsafeDeserialiseFromBytes decode bytes | ||
a `shouldBe` a' |
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.
Two thoughts:
Arbitrary
for roundtrips?- Use
ToCBOR
/FromCBOR
classes more? (I say despite having expressed scepticism of classes perviously)
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 no such classes (which I think is a good thing here). And, providing arbitrary instance for Tx
, Block
and others is trickier than it seems., although, if it just for testing encoder / decoder, we may get away with semantically invalid generators 🤔
61a52c7
to
09224c7
Compare
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 work. One thing to fix before merging is the representation for SignedTx
and a couple of small remarks 👍
src/Cardano/Wallet/Binary.hs
Outdated
encodeTxWitness wit = mempty | ||
<> CBOR.encodeListLen 2 | ||
<> CBOR.encodeWord8 tag | ||
<> CBOR.encodeTag 24 -- "magic" constant |
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.
By the by, I figured while looking at the RFC 7049. 24
corresponds to the semantic "Encoded CBOR data item"
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.
Thought about adding it, but didn't fit on a line, and there are multiple existing Hard-Coded Tag value in cardano-sl
comments. Would go in the module level comment, or a separate solitary comment in that case 🤷♂️
src/Cardano/Wallet/Binary.hs
Outdated
<> mconcat (map encodeOne list) | ||
|
||
sign :: Tx -> [Witness] -> SignedTx | ||
sign tx witnesses = signedTxFromBS . toBS $ encodeSignedTx (tx, witnesses) |
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.
For lack of a better place, I think they're fine here for now. Though here I think the name is misleading. I'd expect a "sign" function to produce the actual witnesses for a given address. Here, it's really just composing things together.
(as mentioned in another comment, I don't think there's any need for that at this stage and encodeSignedTx
is enough on its own).
@@ -318,6 +323,16 @@ newtype Timestamp = Timestamp | |||
} deriving (Show, Generic, Eq, Ord) | |||
|
|||
|
|||
-- | A signed tx is just a base64-encoded string. | |||
newtype SignedTx = SignedTx { signedTx :: 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.
The base64
encoding (or any sort of encoding actually) is good for some contexts; I'd suggest to have our core types work with types directly and perform conversions to base64, base58 or base16 (or anything else) when needed (similarly to what we do with Hash
or Address
).
newtype SignedTx = SignedTx { signedTx :: ByteString }
cborRoundtrip decode encode a = do | ||
let bytes = CBOR.toLazyByteString $ encode a | ||
let a' = unsafeDeserialiseFromBytes decode bytes | ||
a `shouldBe` a' |
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 no such classes (which I think is a good thing here). And, providing arbitrary instance for Tx
, Block
and others is trickier than it seems., although, if it just for testing encoder / decoder, we may get away with semantically invalid generators 🤔
82e18ad
to
35306d7
Compare
35306d7
to
c6eaea7
Compare
return $ ApiT . SignedTx $ bs | ||
where | ||
c :: String -> Either String ByteString | ||
c bs = convertFromBase Base64 (B8.pack bs) |
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.
Now I should definitely add roundtrip tests
c6eaea7
to
028a5ef
Compare
Issue Number
#89
Overview
Adds support for submitting signed transactions to the node / httpBridge.
encodeSignedTx
, encodeWitness,decodeSignedTx
anddecodeWitness
SignedTx <base64>
type andsign :: Tx -> [Witness] -> SignedTx
POST :network/txs/signed
Comments
Binary.hs
, 3) connect the two and add integration tests for submitting signed txs