-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2f9e03
commit c78f206
Showing
15 changed files
with
683 additions
and
11 deletions.
There are no files selected for viewing
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,68 @@ | ||
import { | ||
CdeMinaGenericDatum, | ||
ChainDataExtensionDatum, | ||
ChainDataExtensionMinaGeneric, | ||
} from '@paima/sm'; | ||
import { ChainDataExtensionDatumType } from '@paima/utils'; | ||
|
||
export default async function getCdeData( | ||
minaArchive: string, | ||
extension: ChainDataExtensionMinaGeneric, | ||
fromTimestamp: number, | ||
toTimestamp: number, | ||
getBlockNumber: (minaTimestamp: number) => number, | ||
network: string | ||
): Promise<CdeMinaGenericDatum[]> { | ||
console.log('from-to', fromTimestamp, toTimestamp); | ||
const data = (await fetch(minaArchive, { | ||
method: 'POST', | ||
|
||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
|
||
body: JSON.stringify({ | ||
query: ` | ||
{ | ||
events( | ||
input: { | ||
address: "${extension.address}", | ||
fromTimestamp: "${fromTimestamp}", | ||
toTimestamp: "${toTimestamp}" | ||
} | ||
) { | ||
blockInfo { | ||
height | ||
timestamp | ||
} | ||
eventData { | ||
data | ||
} | ||
} | ||
} | ||
`, | ||
}), | ||
}) | ||
.then(res => res.json()) | ||
.then(res => { | ||
return res; | ||
}) | ||
.then(json => json['data']['events'])) as { | ||
blockInfo: { height: number; timestamp: string }; | ||
eventData: { data: string[] }[]; | ||
}[]; | ||
|
||
return data.flatMap(singleBlockData => | ||
singleBlockData.eventData.flatMap(perTx => | ||
perTx.data.map(txEvent => ({ | ||
cdeId: extension.cdeId, | ||
cdeDatumType: ChainDataExtensionDatumType.MinaGeneric, | ||
blockNumber: getBlockNumber(Number(singleBlockData.blockInfo.timestamp)), | ||
payload: txEvent, | ||
network, | ||
scheduledPrefix: extension.scheduledPrefix, | ||
paginationCursor: { cursor: singleBlockData.blockInfo.timestamp, finished: false }, | ||
})) | ||
) | ||
); | ||
} |
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
Oops, something went wrong.