-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api): inserting simulation of self-transfer
- Loading branch information
Showing
7 changed files
with
287 additions
and
230 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
with tx := (select Transaction filter .id = <uuid>$transaction), | ||
transfers := <array<json>>$transfers, | ||
account := tx.account | ||
select { | ||
prevSimulation := (delete tx.simulation), | ||
tx := ( | ||
update tx set { | ||
executable := <bool>$executable, | ||
simulation := (insert Simulation { | ||
success := <bool>$success, | ||
responses := <array<Bytes>>$responses, | ||
transfers := assert_distinct(( | ||
for transfer in array_unpack(transfers) union ( | ||
insert TransferDetails { | ||
account := account, | ||
from := <Address>transfer['from'], | ||
to := <Address>transfer['to'], | ||
tokenAddress := <UAddress>transfer['tokenAddress'], | ||
amount := <decimal><str>transfer['amount'], | ||
incoming := <bool>transfer['incoming'], | ||
outgoing := <bool>transfer['outgoing'] | ||
} | ||
) if count(transfers) > 0 else {} | ||
)) | ||
}) | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// GENERATED by @edgedb/generate v0.5.3 | ||
|
||
import type {Executor} from "edgedb"; | ||
|
||
export type InsertSimulationArgs = { | ||
readonly "transaction": string; | ||
readonly "transfers": ReadonlyArray<unknown>; | ||
readonly "executable": boolean; | ||
readonly "success": boolean; | ||
readonly "responses": ReadonlyArray<string>; | ||
}; | ||
|
||
export type InsertSimulationReturns = { | ||
"prevSimulation": { | ||
"id": string; | ||
} | null; | ||
"tx": { | ||
"id": string; | ||
} | null; | ||
}; | ||
|
||
export function insertSimulation(client: Executor, args: InsertSimulationArgs): Promise<InsertSimulationReturns> { | ||
return client.queryRequiredSingle(`\ | ||
with tx := (select Transaction filter .id = <uuid>$transaction), | ||
transfers := <array<json>>$transfers, | ||
account := tx.account | ||
select { | ||
prevSimulation := (delete tx.simulation), | ||
tx := ( | ||
update tx set { | ||
executable := <bool>$executable, | ||
simulation := (insert Simulation { | ||
success := <bool>$success, | ||
responses := <array<Bytes>>$responses, | ||
transfers := assert_distinct(( | ||
for transfer in array_unpack(transfers) union ( | ||
insert TransferDetails { | ||
account := account, | ||
from := <Address>transfer['from'], | ||
to := <Address>transfer['to'], | ||
tokenAddress := <UAddress>transfer['tokenAddress'], | ||
amount := <decimal><str>transfer['amount'], | ||
incoming := <bool>transfer['incoming'], | ||
outgoing := <bool>transfer['outgoing'] | ||
} | ||
) if count(transfers) > 0 else {} | ||
)) | ||
}) | ||
} | ||
) | ||
}`, args); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters