-
Notifications
You must be signed in to change notification settings - Fork 550
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
End-to-end agent down to submit #5772
Changes from 3 commits
ffce51d
9a261cb
4938680
df34612
819fe36
bf25f4b
ec58db1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,19 +202,58 @@ let construction_api_payment_through_mempool ~logger ~rosetta_uri | |
Offline.Payloads.req ~logger ~rosetta_uri ~network_response ~operations | ||
~metadata:metadata_res.metadata | ||
in | ||
let%bind parse_res = | ||
let%bind payloads_parse_res = | ||
Offline.Parse.req ~logger ~rosetta_uri ~network_response | ||
~transaction: | ||
(`Unsigned | ||
payloads_res.Construction_payloads_response.unsigned_transaction) | ||
in | ||
if not ([%equal: Operation.t list] operations parse_res.operations) then ( | ||
if not ([%equal: Operation.t list] operations payloads_parse_res.operations) | ||
then ( | ||
[%log debug] | ||
~metadata: | ||
[ ("expected", [%to_yojson: Operation.t list] operations) | ||
; ("actual", [%to_yojson: Operation.t list] parse_res.operations) ] | ||
; ( "actual" | ||
, [%to_yojson: Operation.t list] payloads_parse_res.operations ) ] | ||
"Construction_parse : Expected $expected, after payloads+parse $actual" ; | ||
failwith "Operations are not equal before and after payloads+parse" ) ; | ||
let%bind signature = | ||
Signer.sign ~keys | ||
~unsigned_transaction_string:payloads_res.unsigned_transaction | ||
|> Deferred.return | ||
in | ||
let%bind combine_res = | ||
Offline.Combine.req ~logger ~rosetta_uri ~network_response ~signature | ||
~unsigned_transaction:payloads_res.unsigned_transaction | ||
~public_key_hex_bytes:keys.public_key_hex_bytes | ||
~address:derive_res.address | ||
in | ||
let%bind combine_parse_res = | ||
Offline.Parse.req ~logger ~rosetta_uri ~network_response | ||
~transaction: | ||
(`Signed combine_res.Construction_combine_response.signed_transaction) | ||
in | ||
if not ([%equal: Operation.t list] operations combine_parse_res.operations) | ||
then ( | ||
[%log debug] | ||
~metadata: | ||
[ ("expected", [%to_yojson: Operation.t list] operations) | ||
; ( "actual" | ||
, [%to_yojson: Operation.t list] combine_parse_res.operations ) ] | ||
"Construction_combine : Expected $expected, after combine+parse $actual" ; | ||
failwith "Operations are not equal before and after combine+parse" ) ; | ||
let%bind hash_res = | ||
Offline.Hash.req ~logger ~rosetta_uri ~network_response | ||
~signed_transaction:combine_res.signed_transaction | ||
in | ||
let%bind submit_res = | ||
Peek.Construction.submit ~logger ~rosetta_uri ~network_response | ||
~signed_transaction:combine_res.signed_transaction | ||
in | ||
assert ( | ||
String.equal hash_res.Construction_hash_response.transaction_hash | ||
submit_res.transaction_identifier.hash ) ; | ||
[%log debug] "Construction_submit is finalize" ; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "finalized" |
||
return () | ||
|
||
(* TODO: Break up this function in the next PR *) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ open Core_kernel | |
open Signature_lib | ||
open Lib | ||
module Signature = Coda_base.Signature | ||
module User_command = Coda_base.User_command | ||
|
||
module Keys = struct | ||
type t = {keypair: Keypair.t; public_key_hex_bytes: string} | ||
|
@@ -32,23 +33,25 @@ let sign ~(keys : Keys.t) ~unsigned_transaction_string = | |
try return (Yojson.Safe.from_string unsigned_transaction_string) | ||
with _ -> Result.fail (Errors.create (`Json_parse None)) | ||
in | ||
let%bind unsigned_transaction = | ||
let%map unsigned_transaction = | ||
Transaction.Unsigned.Rendered.of_yojson json | ||
|> Result.map_error ~f:(fun e -> Errors.create (`Json_parse (Some e))) | ||
|> Result.bind ~f:Transaction.Unsigned.of_rendered | ||
in | ||
let user_command_payload = | ||
User_command_info.Partial.to_user_command_payload | ||
~nonce:unsigned_transaction.nonce | ||
unsigned_transaction.Transaction.Unsigned.command | ||
|> Result.ok |> Option.value_exn | ||
in | ||
let signature = | ||
Schnorr.sign keys.keypair.private_key | ||
unsigned_transaction.random_oracle_input | ||
|> Signature.Raw.encode | ||
in | ||
let encoded_signature = Signature.Raw.encode signature in | ||
let signed_transaction = | ||
{ Transaction.Signed.nonce= unsigned_transaction.nonce | ||
; signature= encoded_signature | ||
; command= unsigned_transaction.command } | ||
in | ||
let%map rendered_signed_transaction = | ||
Transaction.Signed.render signed_transaction | ||
let signature' = | ||
User_command.sign_payload keys.keypair.private_key user_command_payload | ||
|> Signature.Raw.encode | ||
in | ||
Transaction.Signed.Rendered.to_yojson rendered_signed_transaction | ||
|> Yojson.Safe.to_string | ||
[%test_eq: string] signature signature' ; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe it would be better to compare the signatures at type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried this originally but it's a bit complicated because we need to derive sexp and compare on too many things. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you can follow up and fix this in another PR if you can see an easy way to do so |
||
signature |
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 you remove the
%bind
and theDeferred.return
?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'm binding here with the Deferred.return to bind over the Result part (we're in the Deferred.Result monad)