@@ -23,6 +23,7 @@ import (
23
23
"fmt"
24
24
"github.com/dapperlabs/flow-playground-api/model"
25
25
"github.com/dapperlabs/flow-playground-api/storage"
26
+ playground "github.com/dapperlabs/flow-playground-api/telemetry"
26
27
27
28
"github.com/getsentry/sentry-go"
28
29
"github.com/google/uuid"
@@ -57,22 +58,27 @@ type Projects struct {
57
58
// Reset the blockchain state.
58
59
func (p * Projects ) Reset (project * model.InternalProject ) ([]* model.InternalAccount , error ) {
59
60
p .cache .reset (project .ID )
61
+ playground .Logger ().Info ("[projects] reset - start" )
60
62
61
63
err := p .store .ResetProjectState (project )
62
64
if err != nil {
63
65
return nil , err
64
66
}
65
67
68
+ playground .Logger ().Info ("[projects] reset - project state reset" )
66
69
accounts , err := p .CreateInitialAccounts (project .ID )
67
70
if err != nil {
68
71
return nil , err
69
72
}
70
73
74
+ playground .Logger ().Info ("[projects] reset - accounts created" )
71
75
return accounts , nil
72
76
}
73
77
74
78
// ExecuteTransaction executes a transaction from the new transaction execution model and persists the execution.
75
79
func (p * Projects ) ExecuteTransaction (execution model.NewTransactionExecution ) (* model.TransactionExecution , error ) {
80
+ playground .Logger ().Info ("[projects] execute transaction - start" )
81
+
76
82
projID := execution .ProjectID
77
83
p .mutex .load (projID ).Lock ()
78
84
defer p .mutex .remove (projID ).Unlock ()
@@ -81,6 +87,8 @@ func (p *Projects) ExecuteTransaction(execution model.NewTransactionExecution) (
81
87
return nil , err
82
88
}
83
89
90
+ playground .Logger ().Info ("[projects] execute transaction - emulator loaded" )
91
+
84
92
signers := make ([]flowsdk.Address , len (execution .Signers ))
85
93
for i , sig := range execution .Signers {
86
94
signers [i ] = sig .ToFlowAddress ()
@@ -95,12 +103,16 @@ func (p *Projects) ExecuteTransaction(execution model.NewTransactionExecution) (
95
103
return nil , err
96
104
}
97
105
106
+ playground .Logger ().Info ("[projects] execute transaction - emulator executed" )
107
+
98
108
exe := model .TransactionExecutionFromFlow (execution .ProjectID , result , tx )
99
109
err = p .store .InsertTransactionExecution (exe )
100
110
if err != nil {
101
111
return nil , err
102
112
}
103
113
114
+ playground .Logger ().Info ("[projects] execute transaction - execution inserted" )
115
+
104
116
return exe , nil
105
117
}
106
118
@@ -188,13 +200,17 @@ func (p *Projects) DeployContract(
188
200
address model.Address ,
189
201
script string ,
190
202
) (* model.Account , error ) {
203
+ playground .Logger ().Info ("[projects] deploy contract - start" )
204
+
191
205
p .mutex .load (projectID ).Lock ()
192
206
defer p .mutex .remove (projectID ).Unlock ()
193
207
emulator , err := p .load (projectID )
194
208
if err != nil {
195
209
return nil , err
196
210
}
197
211
212
+ playground .Logger ().Info ("[projects] deploy contract - emulator loaded" )
213
+
198
214
result , tx , err := emulator .deployContract (address .ToFlowAddress (), script )
199
215
if err != nil {
200
216
return nil , err
@@ -203,12 +219,16 @@ func (p *Projects) DeployContract(
203
219
return nil , result .Error
204
220
}
205
221
222
+ playground .Logger ().Info ("[projects] deploy contract - contract deployed" )
223
+
206
224
exe := model .TransactionExecutionFromFlow (projectID , result , tx )
207
225
err = p .store .InsertTransactionExecution (exe )
208
226
if err != nil {
209
227
return nil , err
210
228
}
211
229
230
+ playground .Logger ().Info ("[projects] deploy contract - execution inserted" )
231
+
212
232
return p .getAccount (projectID , address )
213
233
}
214
234
@@ -218,11 +238,15 @@ func (p *Projects) getAccount(projectID uuid.UUID, address model.Address) (*mode
218
238
return nil , err
219
239
}
220
240
241
+ playground .Logger ().Info ("[projects] get account - emulator loaded" )
242
+
221
243
flowAccount , store , err := emulator .getAccount (address .ToFlowAddress ())
222
244
if err != nil {
223
245
return nil , err
224
246
}
225
247
248
+ playground .Logger ().Info ("[projects] get account - account retrieved from emualator" )
249
+
226
250
jsonStorage , err := json .Marshal (store )
227
251
if err != nil {
228
252
return nil , errors .Wrap (err , "error marshaling account storage" )
@@ -239,12 +263,17 @@ func (p *Projects) getAccount(projectID uuid.UUID, address model.Address) (*mode
239
263
//
240
264
// Do not call this method directly, it is not concurrency safe.
241
265
func (p * Projects ) load (projectID uuid.UUID ) (blockchain , error ) {
266
+
267
+ playground .Logger ().Info ("[projects] load - start" )
268
+
242
269
var executions []* model.TransactionExecution
243
270
err := p .store .GetTransactionExecutionsForProject (projectID , & executions )
244
271
if err != nil {
245
272
return nil , err
246
273
}
247
274
275
+ playground .Logger ().Info ("[projects] load - retrieve executions" )
276
+
248
277
emulator , executions , err := p .cache .get (projectID , executions )
249
278
if emulator == nil || err != nil {
250
279
emulator , err = newEmulator ()
@@ -253,6 +282,8 @@ func (p *Projects) load(projectID uuid.UUID) (blockchain, error) {
253
282
}
254
283
}
255
284
285
+ playground .Logger ().Info ("[projects] load - resolve cache" )
286
+
256
287
for _ , execution := range executions {
257
288
result , _ , err := emulator .executeTransaction (
258
289
execution .Script ,
@@ -282,6 +313,8 @@ func (p *Projects) load(projectID uuid.UUID) (blockchain, error) {
282
313
}
283
314
}
284
315
316
+ playground .Logger ().Info ("[projects] load - executions completed" )
317
+
285
318
p .cache .add (projectID , emulator )
286
319
287
320
return emulator , nil
0 commit comments