Skip to content

Commit

Permalink
Update examples (#41)
Browse files Browse the repository at this point in the history
* fix example scripts

* remove logs

* prettier

* Update examples/pragma/testnet/spot_entry.js

Co-authored-by: 0xevolve <Artevolve@yahoo.com>

* 🎨 prettier

---------

Co-authored-by: 0xevolve <Artevolve@yahoo.com>
  • Loading branch information
apoorvsadana and EvolveArt authored Oct 17, 2023
1 parent 771e578 commit 5c4ac1c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
22 changes: 16 additions & 6 deletions examples/pragma/testnet/future_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const filter = {
],
};

function escapeInvalidCharacters(str) {
return str.replace(/^[\x00-\x1F]+/, "");
}

function decodeEventsInBlock({ header, events }) {
const { blockNumber, blockHash, timestamp } = header;
return events.map(({ event, receipt }) => {
Expand All @@ -31,9 +35,15 @@ function decodeEventsInBlock({ header, events }) {
] = event.data;

// Convert felts to string
const publisherName = shortString.decodeShortString(publisher);
const sourceName = shortString.decodeShortString(source);
const pairIdName = shortString.decodeShortString(pairId);
const publisherName = escapeInvalidCharacters(
shortString.decodeShortString(publisher),
);
const sourceName = escapeInvalidCharacters(
shortString.decodeShortString(source),
);
const pairIdName = escapeInvalidCharacters(
shortString.decodeShortString(pairId),
);

// Convert to snake_case because it works better with postgres.
return {
Expand All @@ -45,18 +55,18 @@ function decodeEventsInBlock({ header, events }) {
block_timestamp: timestamp,
transaction_hash: transactionHash,
price: +price,
timestamp: entryTimestamp,
timestamp: new Date(Number(entryTimestamp) * 1000).toISOString(),
publisher: publisherName,
source: sourceName,
volume: +volume,
expiration_timestamp: expirationTimestamp,
expiration_timestamp: new Date(Number(expirationTimestamp)).toISOString(),
};
});
}

// Configure indexer for streaming Starknet Goerli data starting at the specified block.
export const config = {
streamUrl: "https://mainnet.starknet.a5a.ch",
streamUrl: "https://goerli.starknet.a5a.ch",
startingBlock: 865000,
network: "starknet",
filter,
Expand Down
22 changes: 16 additions & 6 deletions examples/pragma/testnet/spot_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ const filter = {
],
};

function decodeTransfersInBlock({ header, events }) {
function escapeInvalidCharacters(str) {
return str.replace(/^[\x00-\x1F]+/, "");
}

function decodeEventsInBlock({ header, events }) {
const { blockNumber, blockHash, timestamp } = header;
return events.map(({ event, receipt }) => {
const { transactionHash } = receipt;
Expand All @@ -24,9 +28,15 @@ function decodeTransfersInBlock({ header, events }) {
event.data;

// Convert felts to string
const publisherName = shortString.decodeShortString(publisher);
const sourceName = shortString.decodeShortString(source);
const pairIdName = shortString.decodeShortString(pairId);
const publisherName = escapeInvalidCharacters(
shortString.decodeShortString(publisher),
);
const sourceName = escapeInvalidCharacters(
shortString.decodeShortString(source),
);
const pairIdName = escapeInvalidCharacters(
shortString.decodeShortString(pairId),
);

// Convert to snake_case because it works better with postgres.
return {
Expand All @@ -38,7 +48,7 @@ function decodeTransfersInBlock({ header, events }) {
block_timestamp: timestamp,
transaction_hash: transactionHash,
price: +price,
timestamp: entryTimestamp,
timestamp: new Date(Number(entryTimestamp) * 1000).toISOString(),
publisher: publisherName,
source: sourceName,
volume: +volume,
Expand All @@ -48,7 +58,7 @@ function decodeTransfersInBlock({ header, events }) {

// Configure indexer for streaming Starknet Goerli data starting at the specified block.
export const config = {
streamUrl: "https://mainnet.starknet.a5a.ch",
streamUrl: "https://goerli.starknet.a5a.ch",
startingBlock: 865000,
network: "starknet",
filter,
Expand Down

0 comments on commit 5c4ac1c

Please sign in to comment.