@@ -27,15 +27,7 @@ import (
2727 "google.golang.org/grpc"
2828)
2929
30- type SignerRole string
31-
32- const (
33- SignerRoleAuthorizer SignerRole = "authorizer"
34- SignerRoleProposer SignerRole = "proposer"
35- SignerRolePayer SignerRole = "payer"
36- )
37-
38- func PrepareTransaction (host string , signerAccount * Account , tx * flow.Transaction , payer flow.Address ) * flow.Transaction {
30+ func SendTransaction (host string , signerAccount * Account , tx * flow.Transaction , withResults bool ) {
3931 ctx := context .Background ()
4032
4133 flowClient , err := client .New (host , grpc .WithInsecure ())
@@ -62,21 +54,13 @@ func PrepareTransaction(host string, signerAccount *Account, tx *flow.Transactio
6254
6355 tx .SetReferenceBlockID (sealed .ID ).
6456 SetProposalKey (signerAddress , accountKey .Index , accountKey .SequenceNumber ).
65- SetPayer (payer )
66-
67- return tx
68- }
69-
70- func SendTransaction (host string , signerAccount * Account , tx * flow.Transaction , withResults bool ) {
71- ctx := context .Background ()
57+ SetPayer (signerAddress )
7258
73- flowClient , err := client . New ( host , grpc . WithInsecure () )
59+ err = tx . SignEnvelope ( signerAddress , accountKey . Index , signerAccount . Signer )
7460 if err != nil {
75- Exitf (1 , "Failed to connect to host : %s" , err )
61+ Exitf (1 , "Failed to sign transaction : %s" , err )
7662 }
7763
78- tx = signTransaction (ctx , flowClient , signerAccount , SignerRolePayer , tx )
79-
8064 fmt .Printf ("Submitting transaction with ID %s ...\n " , tx .ID ())
8165
8266 err = flowClient .SendTransaction (context .Background (), * tx )
@@ -93,51 +77,3 @@ func SendTransaction(host string, signerAccount *Account, tx *flow.Transaction,
9377 printTxResult (tx , res , true )
9478 }
9579}
96-
97- func PrepareAndSendTransaction (host string , signerAccount * Account , tx * flow.Transaction , payer flow.Address , withResults bool ) {
98- preparedTx := PrepareTransaction (host , signerAccount , tx , payer )
99- SendTransaction (host , signerAccount , preparedTx , withResults )
100- }
101-
102- func SignTransaction (host string , signerAccount * Account , signerRole SignerRole , tx * flow.Transaction ) * flow.Transaction {
103- ctx := context .Background ()
104-
105- flowClient , err := client .New (host , grpc .WithInsecure ())
106- if err != nil {
107- Exitf (1 , "Failed to connect to host: %s" , err )
108- }
109-
110- tx = signTransaction (ctx , flowClient , signerAccount , signerRole , tx )
111- return tx
112- }
113-
114- func signTransaction (
115- ctx context.Context ,
116- flowClient * client.Client ,
117- signerAccount * Account ,
118- signerRole SignerRole ,
119- tx * flow.Transaction ,
120- ) * flow.Transaction {
121- signerAddress := signerAccount .Address
122- account , err := flowClient .GetAccount (ctx , signerAddress )
123- if err != nil {
124- Exitf (1 , "Failed to get account with address %s: %s" , signerAddress .Hex (), err )
125- }
126- accountKey := account .Keys [signerAccount .KeyIndex ]
127- switch signerRole {
128- case SignerRoleAuthorizer :
129- err := tx .SignPayload (signerAddress , accountKey .Index , signerAccount .Signer )
130- if err != nil {
131- Exitf (1 , "Failed to sign transaction: %s" , err )
132- }
133- case SignerRolePayer :
134- err := tx .SignEnvelope (signerAddress , accountKey .Index , signerAccount .Signer )
135- if err != nil {
136- Exitf (1 , "Failed to sign transaction: %s" , err )
137- }
138- default :
139- Exitf (1 , "Failed to sign transaction: unknown signer role %s" , signerRole )
140- }
141-
142- return tx
143- }
0 commit comments