@develit-services/blockchain 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/database/schema.cjs +2 -2
- package/dist/database/schema.d.cts +1 -1
- package/dist/database/schema.d.mts +1 -1
- package/dist/database/schema.d.ts +1 -1
- package/dist/database/schema.mjs +1 -1
- package/dist/export/worker.cjs +24 -2
- package/dist/export/worker.d.cts +7 -4
- package/dist/export/worker.d.mts +7 -4
- package/dist/export/worker.d.ts +7 -4
- package/dist/export/worker.mjs +25 -3
- package/dist/export/workflows.cjs +109 -0
- package/dist/export/workflows.d.cts +10 -0
- package/dist/export/workflows.d.mts +10 -0
- package/dist/export/workflows.d.ts +10 -0
- package/dist/export/workflows.mjs +107 -0
- package/dist/export/wrangler.cjs +7 -6
- package/dist/export/wrangler.d.cts +6 -1
- package/dist/export/wrangler.d.mts +6 -1
- package/dist/export/wrangler.d.ts +6 -1
- package/dist/export/wrangler.mjs +7 -6
- package/dist/shared/blockchain.4u7GTzW9.d.cts +20 -0
- package/dist/shared/blockchain.4u7GTzW9.d.mts +20 -0
- package/dist/shared/blockchain.4u7GTzW9.d.ts +20 -0
- package/dist/shared/blockchain.55Jm5hWs.mjs +11 -0
- package/dist/shared/blockchain.BalTLss2.d.cts +12 -0
- package/dist/shared/blockchain.BalTLss2.d.mts +12 -0
- package/dist/shared/blockchain.BalTLss2.d.ts +12 -0
- package/dist/shared/blockchain.ByChhKtd.d.cts +217 -0
- package/dist/shared/blockchain.ByChhKtd.d.mts +217 -0
- package/dist/shared/blockchain.ByChhKtd.d.ts +217 -0
- package/dist/shared/blockchain.D63utaAU.cjs +14 -0
- package/dist/shared/blockchain.DmhmTTL_.mjs +17 -0
- package/dist/shared/blockchain.JxC5JMLI.cjs +20 -0
- package/dist/types.cjs +7 -0
- package/dist/types.d.cts +3 -20
- package/dist/types.d.mts +3 -20
- package/dist/types.d.ts +3 -20
- package/dist/types.mjs +2 -1
- package/package.json +13 -8
- package/dist/shared/blockchain.BPNOynrU.cjs +0 -16
- package/dist/shared/blockchain.CEE7tZvq.mjs +0 -13
- package/dist/shared/blockchain.ODFBS3S9.d.cts +0 -88
- package/dist/shared/blockchain.ODFBS3S9.d.mts +0 -88
- package/dist/shared/blockchain.ODFBS3S9.d.ts +0 -88
package/dist/database/schema.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const database_schema = require('../shared/blockchain.
|
|
3
|
+
const database_schema = require('../shared/blockchain.JxC5JMLI.cjs');
|
|
4
4
|
require('@develit-io/backend-sdk');
|
|
5
5
|
require('drizzle-orm/sqlite-core');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
exports.
|
|
9
|
+
exports.address = database_schema.address;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { a as address } from '../shared/blockchain.ByChhKtd.cjs';
|
|
2
2
|
import 'drizzle-orm/sqlite-core';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { a as address } from '../shared/blockchain.ByChhKtd.mjs';
|
|
2
2
|
import 'drizzle-orm/sqlite-core';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { a as address } from '../shared/blockchain.ByChhKtd.js';
|
|
2
2
|
import 'drizzle-orm/sqlite-core';
|
package/dist/database/schema.mjs
CHANGED
package/dist/export/worker.cjs
CHANGED
|
@@ -3,20 +3,24 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const backendSdk = require('@develit-io/backend-sdk');
|
|
6
|
-
const database_schema = require('../shared/blockchain.
|
|
6
|
+
const database_schema = require('../shared/blockchain.JxC5JMLI.cjs');
|
|
7
7
|
require('drizzle-orm');
|
|
8
|
+
const syncAddress = require('../shared/blockchain.D63utaAU.cjs');
|
|
8
9
|
const cloudflare_workers = require('cloudflare:workers');
|
|
9
10
|
const d1 = require('drizzle-orm/d1');
|
|
10
11
|
require('drizzle-orm/sqlite-core');
|
|
12
|
+
require('zod');
|
|
11
13
|
|
|
12
14
|
const tables = database_schema.schema;
|
|
13
15
|
|
|
16
|
+
var __defProp = Object.defineProperty;
|
|
14
17
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
15
18
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
16
19
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
17
20
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
18
21
|
if (decorator = decorators[i])
|
|
19
|
-
result = (decorator(result)) || result;
|
|
22
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
23
|
+
if (kind && result) __defProp(target, key, result);
|
|
20
24
|
return result;
|
|
21
25
|
};
|
|
22
26
|
let BlockchainServiceBase = class extends backendSdk.develitWorker(
|
|
@@ -26,7 +30,25 @@ let BlockchainServiceBase = class extends backendSdk.develitWorker(
|
|
|
26
30
|
super(ctx, env);
|
|
27
31
|
this.db = d1.drizzle(this.env.BLOCKCHAIN_D1, { schema: tables });
|
|
28
32
|
}
|
|
33
|
+
async syncAddress(input) {
|
|
34
|
+
return this.handleAction(
|
|
35
|
+
{ data: input, schema: syncAddress.syncAddressInputSchema },
|
|
36
|
+
{ successMessage: "Address sync workflow started" },
|
|
37
|
+
async ({ addressId }) => {
|
|
38
|
+
await this.env.SYNC_ADDRESS_TRANSACTIONS_WORKFLOW.create({
|
|
39
|
+
id: addressId,
|
|
40
|
+
params: {
|
|
41
|
+
addressId
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
}
|
|
29
48
|
};
|
|
49
|
+
__decorateClass([
|
|
50
|
+
backendSdk.action("sync-address")
|
|
51
|
+
], BlockchainServiceBase.prototype, "syncAddress", 1);
|
|
30
52
|
BlockchainServiceBase = __decorateClass([
|
|
31
53
|
backendSdk.service("blockchain")
|
|
32
54
|
], BlockchainServiceBase);
|
package/dist/export/worker.d.cts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { s as schema } from '../shared/blockchain.
|
|
3
|
-
import {
|
|
1
|
+
import { IRPCResponse } from '@develit-io/backend-sdk';
|
|
2
|
+
import { s as schema } from '../shared/blockchain.ByChhKtd.cjs';
|
|
3
|
+
import { S as SyncAddressInput, b as SyncAddressOutput } from '../shared/blockchain.BalTLss2.cjs';
|
|
4
4
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
5
|
+
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
5
6
|
import 'drizzle-orm/sqlite-core';
|
|
7
|
+
import 'zod';
|
|
6
8
|
|
|
7
9
|
declare const tables: typeof schema;
|
|
8
10
|
|
|
9
|
-
declare const BlockchainServiceBase_base:
|
|
11
|
+
declare const BlockchainServiceBase_base: any;
|
|
10
12
|
declare class BlockchainServiceBase extends BlockchainServiceBase_base {
|
|
11
13
|
readonly db: DrizzleD1Database<typeof tables>;
|
|
12
14
|
constructor(ctx: ExecutionContext, env: BlockchainEnv);
|
|
15
|
+
syncAddress(input: SyncAddressInput): Promise<IRPCResponse<SyncAddressOutput>>;
|
|
13
16
|
}
|
|
14
17
|
declare function defineBlockchainService(): new (ctx: ExecutionContext, env: BlockchainEnv) => BlockchainServiceBase;
|
|
15
18
|
|
package/dist/export/worker.d.mts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { s as schema } from '../shared/blockchain.
|
|
3
|
-
import {
|
|
1
|
+
import { IRPCResponse } from '@develit-io/backend-sdk';
|
|
2
|
+
import { s as schema } from '../shared/blockchain.ByChhKtd.mjs';
|
|
3
|
+
import { S as SyncAddressInput, b as SyncAddressOutput } from '../shared/blockchain.BalTLss2.mjs';
|
|
4
4
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
5
|
+
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
5
6
|
import 'drizzle-orm/sqlite-core';
|
|
7
|
+
import 'zod';
|
|
6
8
|
|
|
7
9
|
declare const tables: typeof schema;
|
|
8
10
|
|
|
9
|
-
declare const BlockchainServiceBase_base:
|
|
11
|
+
declare const BlockchainServiceBase_base: any;
|
|
10
12
|
declare class BlockchainServiceBase extends BlockchainServiceBase_base {
|
|
11
13
|
readonly db: DrizzleD1Database<typeof tables>;
|
|
12
14
|
constructor(ctx: ExecutionContext, env: BlockchainEnv);
|
|
15
|
+
syncAddress(input: SyncAddressInput): Promise<IRPCResponse<SyncAddressOutput>>;
|
|
13
16
|
}
|
|
14
17
|
declare function defineBlockchainService(): new (ctx: ExecutionContext, env: BlockchainEnv) => BlockchainServiceBase;
|
|
15
18
|
|
package/dist/export/worker.d.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { s as schema } from '../shared/blockchain.
|
|
3
|
-
import {
|
|
1
|
+
import { IRPCResponse } from '@develit-io/backend-sdk';
|
|
2
|
+
import { s as schema } from '../shared/blockchain.ByChhKtd.js';
|
|
3
|
+
import { S as SyncAddressInput, b as SyncAddressOutput } from '../shared/blockchain.BalTLss2.js';
|
|
4
4
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
5
|
+
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
5
6
|
import 'drizzle-orm/sqlite-core';
|
|
7
|
+
import 'zod';
|
|
6
8
|
|
|
7
9
|
declare const tables: typeof schema;
|
|
8
10
|
|
|
9
|
-
declare const BlockchainServiceBase_base:
|
|
11
|
+
declare const BlockchainServiceBase_base: any;
|
|
10
12
|
declare class BlockchainServiceBase extends BlockchainServiceBase_base {
|
|
11
13
|
readonly db: DrizzleD1Database<typeof tables>;
|
|
12
14
|
constructor(ctx: ExecutionContext, env: BlockchainEnv);
|
|
15
|
+
syncAddress(input: SyncAddressInput): Promise<IRPCResponse<SyncAddressOutput>>;
|
|
13
16
|
}
|
|
14
17
|
declare function defineBlockchainService(): new (ctx: ExecutionContext, env: BlockchainEnv) => BlockchainServiceBase;
|
|
15
18
|
|
package/dist/export/worker.mjs
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import { develitWorker, service } from '@develit-io/backend-sdk';
|
|
2
|
-
import { s as schema } from '../shared/blockchain.
|
|
1
|
+
import { develitWorker, action, service } from '@develit-io/backend-sdk';
|
|
2
|
+
import { s as schema } from '../shared/blockchain.DmhmTTL_.mjs';
|
|
3
3
|
import 'drizzle-orm';
|
|
4
|
+
import { s as syncAddressInputSchema } from '../shared/blockchain.55Jm5hWs.mjs';
|
|
4
5
|
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
5
6
|
import { drizzle } from 'drizzle-orm/d1';
|
|
6
7
|
import 'drizzle-orm/sqlite-core';
|
|
8
|
+
import 'zod';
|
|
7
9
|
|
|
8
10
|
const tables = schema;
|
|
9
11
|
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
10
13
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
14
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
12
15
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
13
16
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
14
17
|
if (decorator = decorators[i])
|
|
15
|
-
result = (decorator(result)) || result;
|
|
18
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
19
|
+
if (kind && result) __defProp(target, key, result);
|
|
16
20
|
return result;
|
|
17
21
|
};
|
|
18
22
|
let BlockchainServiceBase = class extends develitWorker(
|
|
@@ -22,7 +26,25 @@ let BlockchainServiceBase = class extends develitWorker(
|
|
|
22
26
|
super(ctx, env);
|
|
23
27
|
this.db = drizzle(this.env.BLOCKCHAIN_D1, { schema: tables });
|
|
24
28
|
}
|
|
29
|
+
async syncAddress(input) {
|
|
30
|
+
return this.handleAction(
|
|
31
|
+
{ data: input, schema: syncAddressInputSchema },
|
|
32
|
+
{ successMessage: "Address sync workflow started" },
|
|
33
|
+
async ({ addressId }) => {
|
|
34
|
+
await this.env.SYNC_ADDRESS_TRANSACTIONS_WORKFLOW.create({
|
|
35
|
+
id: addressId,
|
|
36
|
+
params: {
|
|
37
|
+
addressId
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
}
|
|
25
44
|
};
|
|
45
|
+
__decorateClass([
|
|
46
|
+
action("sync-address")
|
|
47
|
+
], BlockchainServiceBase.prototype, "syncAddress", 1);
|
|
26
48
|
BlockchainServiceBase = __decorateClass([
|
|
27
49
|
service("blockchain")
|
|
28
50
|
], BlockchainServiceBase);
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const cloudflare_workers = require('cloudflare:workers');
|
|
4
|
+
const cloudflare_workflows = require('cloudflare:workflows');
|
|
5
|
+
const viem = require('viem');
|
|
6
|
+
const chains = require('viem/chains');
|
|
7
|
+
|
|
8
|
+
const TEST_ADDRESSES = {
|
|
9
|
+
"faucet-1": {
|
|
10
|
+
id: "faucet-1",
|
|
11
|
+
address: "0xc959483dba39aa9e78757139af0e9a2edeb3f42d",
|
|
12
|
+
blockchain: "ethereum",
|
|
13
|
+
network: "sepolia",
|
|
14
|
+
syncIntervalS: 60,
|
|
15
|
+
lastSyncedBlock: null
|
|
16
|
+
},
|
|
17
|
+
"faucet-2": {
|
|
18
|
+
id: "faucet-2",
|
|
19
|
+
address: "0x1f885520b7bd528e46b390040f12e753dce43004",
|
|
20
|
+
blockchain: "ethereum",
|
|
21
|
+
network: "sepolia",
|
|
22
|
+
syncIntervalS: 90,
|
|
23
|
+
lastSyncedBlock: null
|
|
24
|
+
},
|
|
25
|
+
"vitalik-test": {
|
|
26
|
+
id: "vitalik-test",
|
|
27
|
+
address: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
|
|
28
|
+
blockchain: "ethereum",
|
|
29
|
+
network: "sepolia",
|
|
30
|
+
syncIntervalS: 120,
|
|
31
|
+
lastSyncedBlock: null
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
class BlockchainSyncAddressTransactions extends cloudflare_workers.WorkflowEntrypoint {
|
|
35
|
+
async run(event, step) {
|
|
36
|
+
const { addressId } = event.payload;
|
|
37
|
+
while (true) {
|
|
38
|
+
const address = await step.do("load address", async () => {
|
|
39
|
+
const address2 = TEST_ADDRESSES[addressId];
|
|
40
|
+
if (!address2) {
|
|
41
|
+
throw new cloudflare_workflows.NonRetryableError(
|
|
42
|
+
`Blockchain address not found: ${addressId}.`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
return address2;
|
|
46
|
+
});
|
|
47
|
+
await step.do(
|
|
48
|
+
"fetch address transactions",
|
|
49
|
+
{
|
|
50
|
+
retries: { limit: 5, delay: 2e3, backoff: "constant" },
|
|
51
|
+
timeout: "30 seconds"
|
|
52
|
+
},
|
|
53
|
+
async () => {
|
|
54
|
+
const client = viem.createPublicClient({
|
|
55
|
+
chain: chains.sepolia,
|
|
56
|
+
transport: viem.http()
|
|
57
|
+
});
|
|
58
|
+
const currentBlock = await client.getBlockNumber();
|
|
59
|
+
const startBlock = address.lastSyncedBlock ? BigInt(address.lastSyncedBlock) + BigInt(1) : currentBlock - BigInt(10);
|
|
60
|
+
const endBlock = currentBlock;
|
|
61
|
+
console.log(
|
|
62
|
+
`\u{1F50D} Scanning blocks ${startBlock} to ${endBlock} for address ${address.address}`
|
|
63
|
+
);
|
|
64
|
+
const allTransactions = [];
|
|
65
|
+
for (let blockNum = startBlock; blockNum <= endBlock; blockNum++) {
|
|
66
|
+
const block = await client.getBlock({
|
|
67
|
+
blockNumber: blockNum,
|
|
68
|
+
includeTransactions: true
|
|
69
|
+
});
|
|
70
|
+
for (const tx of block.transactions) {
|
|
71
|
+
if (typeof tx === "string") continue;
|
|
72
|
+
if (tx.from.toLowerCase() === address.address.toLowerCase() || tx.to?.toLowerCase() === address.address.toLowerCase()) {
|
|
73
|
+
const receipt = await client.getTransactionReceipt({
|
|
74
|
+
hash: tx.hash
|
|
75
|
+
});
|
|
76
|
+
allTransactions.push({
|
|
77
|
+
hash: tx.hash,
|
|
78
|
+
from: tx.from,
|
|
79
|
+
to: tx.to,
|
|
80
|
+
value: tx.value.toString(),
|
|
81
|
+
blockNumber: block.number.toString(),
|
|
82
|
+
blockHash: block.hash,
|
|
83
|
+
gasUsed: receipt.gasUsed.toString(),
|
|
84
|
+
gasPrice: tx.gasPrice?.toString(),
|
|
85
|
+
timestamp: Number(block.timestamp),
|
|
86
|
+
status: receipt.status === "success" ? "success" : "reverted"
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
console.log(`\u2705 Sync complete for ${address.address}`);
|
|
92
|
+
console.log(` Found ${allTransactions.length} transactions`);
|
|
93
|
+
console.log(` Blocks scanned: ${startBlock} to ${endBlock}`);
|
|
94
|
+
if (allTransactions.length > 0) {
|
|
95
|
+
console.log("Transactions:");
|
|
96
|
+
console.log(JSON.stringify(allTransactions));
|
|
97
|
+
}
|
|
98
|
+
return allTransactions;
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
await step.sleep(
|
|
102
|
+
"sleep until next sync",
|
|
103
|
+
`${address.syncIntervalS} seconds`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
exports.BlockchainSyncAddressTransactions = BlockchainSyncAddressTransactions;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from 'cloudflare:workers';
|
|
2
|
+
|
|
3
|
+
type Params = {
|
|
4
|
+
addressId: string;
|
|
5
|
+
};
|
|
6
|
+
declare class BlockchainSyncAddressTransactions extends WorkflowEntrypoint<BlockchainEnv, Params> {
|
|
7
|
+
run(event: WorkflowEvent<Params>, step: WorkflowStep): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { BlockchainSyncAddressTransactions };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from 'cloudflare:workers';
|
|
2
|
+
|
|
3
|
+
type Params = {
|
|
4
|
+
addressId: string;
|
|
5
|
+
};
|
|
6
|
+
declare class BlockchainSyncAddressTransactions extends WorkflowEntrypoint<BlockchainEnv, Params> {
|
|
7
|
+
run(event: WorkflowEvent<Params>, step: WorkflowStep): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { BlockchainSyncAddressTransactions };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from 'cloudflare:workers';
|
|
2
|
+
|
|
3
|
+
type Params = {
|
|
4
|
+
addressId: string;
|
|
5
|
+
};
|
|
6
|
+
declare class BlockchainSyncAddressTransactions extends WorkflowEntrypoint<BlockchainEnv, Params> {
|
|
7
|
+
run(event: WorkflowEvent<Params>, step: WorkflowStep): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { BlockchainSyncAddressTransactions };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { WorkflowEntrypoint } from 'cloudflare:workers';
|
|
2
|
+
import { NonRetryableError } from 'cloudflare:workflows';
|
|
3
|
+
import { createPublicClient, http } from 'viem';
|
|
4
|
+
import { sepolia } from 'viem/chains';
|
|
5
|
+
|
|
6
|
+
const TEST_ADDRESSES = {
|
|
7
|
+
"faucet-1": {
|
|
8
|
+
id: "faucet-1",
|
|
9
|
+
address: "0xc959483dba39aa9e78757139af0e9a2edeb3f42d",
|
|
10
|
+
blockchain: "ethereum",
|
|
11
|
+
network: "sepolia",
|
|
12
|
+
syncIntervalS: 60,
|
|
13
|
+
lastSyncedBlock: null
|
|
14
|
+
},
|
|
15
|
+
"faucet-2": {
|
|
16
|
+
id: "faucet-2",
|
|
17
|
+
address: "0x1f885520b7bd528e46b390040f12e753dce43004",
|
|
18
|
+
blockchain: "ethereum",
|
|
19
|
+
network: "sepolia",
|
|
20
|
+
syncIntervalS: 90,
|
|
21
|
+
lastSyncedBlock: null
|
|
22
|
+
},
|
|
23
|
+
"vitalik-test": {
|
|
24
|
+
id: "vitalik-test",
|
|
25
|
+
address: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
|
|
26
|
+
blockchain: "ethereum",
|
|
27
|
+
network: "sepolia",
|
|
28
|
+
syncIntervalS: 120,
|
|
29
|
+
lastSyncedBlock: null
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
class BlockchainSyncAddressTransactions extends WorkflowEntrypoint {
|
|
33
|
+
async run(event, step) {
|
|
34
|
+
const { addressId } = event.payload;
|
|
35
|
+
while (true) {
|
|
36
|
+
const address = await step.do("load address", async () => {
|
|
37
|
+
const address2 = TEST_ADDRESSES[addressId];
|
|
38
|
+
if (!address2) {
|
|
39
|
+
throw new NonRetryableError(
|
|
40
|
+
`Blockchain address not found: ${addressId}.`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return address2;
|
|
44
|
+
});
|
|
45
|
+
await step.do(
|
|
46
|
+
"fetch address transactions",
|
|
47
|
+
{
|
|
48
|
+
retries: { limit: 5, delay: 2e3, backoff: "constant" },
|
|
49
|
+
timeout: "30 seconds"
|
|
50
|
+
},
|
|
51
|
+
async () => {
|
|
52
|
+
const client = createPublicClient({
|
|
53
|
+
chain: sepolia,
|
|
54
|
+
transport: http()
|
|
55
|
+
});
|
|
56
|
+
const currentBlock = await client.getBlockNumber();
|
|
57
|
+
const startBlock = address.lastSyncedBlock ? BigInt(address.lastSyncedBlock) + BigInt(1) : currentBlock - BigInt(10);
|
|
58
|
+
const endBlock = currentBlock;
|
|
59
|
+
console.log(
|
|
60
|
+
`\u{1F50D} Scanning blocks ${startBlock} to ${endBlock} for address ${address.address}`
|
|
61
|
+
);
|
|
62
|
+
const allTransactions = [];
|
|
63
|
+
for (let blockNum = startBlock; blockNum <= endBlock; blockNum++) {
|
|
64
|
+
const block = await client.getBlock({
|
|
65
|
+
blockNumber: blockNum,
|
|
66
|
+
includeTransactions: true
|
|
67
|
+
});
|
|
68
|
+
for (const tx of block.transactions) {
|
|
69
|
+
if (typeof tx === "string") continue;
|
|
70
|
+
if (tx.from.toLowerCase() === address.address.toLowerCase() || tx.to?.toLowerCase() === address.address.toLowerCase()) {
|
|
71
|
+
const receipt = await client.getTransactionReceipt({
|
|
72
|
+
hash: tx.hash
|
|
73
|
+
});
|
|
74
|
+
allTransactions.push({
|
|
75
|
+
hash: tx.hash,
|
|
76
|
+
from: tx.from,
|
|
77
|
+
to: tx.to,
|
|
78
|
+
value: tx.value.toString(),
|
|
79
|
+
blockNumber: block.number.toString(),
|
|
80
|
+
blockHash: block.hash,
|
|
81
|
+
gasUsed: receipt.gasUsed.toString(),
|
|
82
|
+
gasPrice: tx.gasPrice?.toString(),
|
|
83
|
+
timestamp: Number(block.timestamp),
|
|
84
|
+
status: receipt.status === "success" ? "success" : "reverted"
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
console.log(`\u2705 Sync complete for ${address.address}`);
|
|
90
|
+
console.log(` Found ${allTransactions.length} transactions`);
|
|
91
|
+
console.log(` Blocks scanned: ${startBlock} to ${endBlock}`);
|
|
92
|
+
if (allTransactions.length > 0) {
|
|
93
|
+
console.log("Transactions:");
|
|
94
|
+
console.log(JSON.stringify(allTransactions));
|
|
95
|
+
}
|
|
96
|
+
return allTransactions;
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
await step.sleep(
|
|
100
|
+
"sleep until next sync",
|
|
101
|
+
`${address.syncIntervalS} seconds`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { BlockchainSyncAddressTransactions };
|
package/dist/export/wrangler.cjs
CHANGED
|
@@ -26,6 +26,13 @@ function defineBlockchainServiceWrangler(config) {
|
|
|
26
26
|
migrations_dir: "./src/database/migrations"
|
|
27
27
|
}
|
|
28
28
|
],
|
|
29
|
+
workflows: [
|
|
30
|
+
{
|
|
31
|
+
binding: "SYNC_ADDRESS_TRANSACTIONS_WORKFLOW",
|
|
32
|
+
name: `${project}-blockchain-sync-address-transactions`,
|
|
33
|
+
class_name: "BlockchainSyncAddressTransactions"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
29
36
|
env: {}
|
|
30
37
|
};
|
|
31
38
|
for (const [envName, envCfg] of Object.entries(envs).filter(
|
|
@@ -36,12 +43,6 @@ function defineBlockchainServiceWrangler(config) {
|
|
|
36
43
|
...envCfg.vars,
|
|
37
44
|
ENVIRONMENT: envName
|
|
38
45
|
},
|
|
39
|
-
services: [
|
|
40
|
-
{
|
|
41
|
-
binding: "SECRETS_STORE",
|
|
42
|
-
service: `${project}-secrets-store-${envName}`
|
|
43
|
-
}
|
|
44
|
-
],
|
|
45
46
|
d1_databases: [
|
|
46
47
|
{
|
|
47
48
|
binding: "BLOCKCHAIN_D1",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BlockchainServiceWranglerConfig } from '../
|
|
1
|
+
import { a as BlockchainServiceWranglerConfig } from '../shared/blockchain.4u7GTzW9.cjs';
|
|
2
2
|
|
|
3
3
|
declare function defineBlockchainServiceWrangler(config: BlockchainServiceWranglerConfig): {
|
|
4
4
|
vars: {
|
|
@@ -14,6 +14,11 @@ declare function defineBlockchainServiceWrangler(config: BlockchainServiceWrangl
|
|
|
14
14
|
database_id: string;
|
|
15
15
|
migrations_dir: string;
|
|
16
16
|
}[];
|
|
17
|
+
workflows: {
|
|
18
|
+
binding: string;
|
|
19
|
+
name: string;
|
|
20
|
+
class_name: string;
|
|
21
|
+
}[];
|
|
17
22
|
env: Record<string, unknown>;
|
|
18
23
|
$schema: string;
|
|
19
24
|
name: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BlockchainServiceWranglerConfig } from '../
|
|
1
|
+
import { a as BlockchainServiceWranglerConfig } from '../shared/blockchain.4u7GTzW9.mjs';
|
|
2
2
|
|
|
3
3
|
declare function defineBlockchainServiceWrangler(config: BlockchainServiceWranglerConfig): {
|
|
4
4
|
vars: {
|
|
@@ -14,6 +14,11 @@ declare function defineBlockchainServiceWrangler(config: BlockchainServiceWrangl
|
|
|
14
14
|
database_id: string;
|
|
15
15
|
migrations_dir: string;
|
|
16
16
|
}[];
|
|
17
|
+
workflows: {
|
|
18
|
+
binding: string;
|
|
19
|
+
name: string;
|
|
20
|
+
class_name: string;
|
|
21
|
+
}[];
|
|
17
22
|
env: Record<string, unknown>;
|
|
18
23
|
$schema: string;
|
|
19
24
|
name: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BlockchainServiceWranglerConfig } from '../
|
|
1
|
+
import { a as BlockchainServiceWranglerConfig } from '../shared/blockchain.4u7GTzW9.js';
|
|
2
2
|
|
|
3
3
|
declare function defineBlockchainServiceWrangler(config: BlockchainServiceWranglerConfig): {
|
|
4
4
|
vars: {
|
|
@@ -14,6 +14,11 @@ declare function defineBlockchainServiceWrangler(config: BlockchainServiceWrangl
|
|
|
14
14
|
database_id: string;
|
|
15
15
|
migrations_dir: string;
|
|
16
16
|
}[];
|
|
17
|
+
workflows: {
|
|
18
|
+
binding: string;
|
|
19
|
+
name: string;
|
|
20
|
+
class_name: string;
|
|
21
|
+
}[];
|
|
17
22
|
env: Record<string, unknown>;
|
|
18
23
|
$schema: string;
|
|
19
24
|
name: string;
|
package/dist/export/wrangler.mjs
CHANGED
|
@@ -24,6 +24,13 @@ function defineBlockchainServiceWrangler(config) {
|
|
|
24
24
|
migrations_dir: "./src/database/migrations"
|
|
25
25
|
}
|
|
26
26
|
],
|
|
27
|
+
workflows: [
|
|
28
|
+
{
|
|
29
|
+
binding: "SYNC_ADDRESS_TRANSACTIONS_WORKFLOW",
|
|
30
|
+
name: `${project}-blockchain-sync-address-transactions`,
|
|
31
|
+
class_name: "BlockchainSyncAddressTransactions"
|
|
32
|
+
}
|
|
33
|
+
],
|
|
27
34
|
env: {}
|
|
28
35
|
};
|
|
29
36
|
for (const [envName, envCfg] of Object.entries(envs).filter(
|
|
@@ -34,12 +41,6 @@ function defineBlockchainServiceWrangler(config) {
|
|
|
34
41
|
...envCfg.vars,
|
|
35
42
|
ENVIRONMENT: envName
|
|
36
43
|
},
|
|
37
|
-
services: [
|
|
38
|
-
{
|
|
39
|
-
binding: "SECRETS_STORE",
|
|
40
|
-
service: `${project}-secrets-store-${envName}`
|
|
41
|
-
}
|
|
42
|
-
],
|
|
43
44
|
d1_databases: [
|
|
44
45
|
{
|
|
45
46
|
binding: "BLOCKCHAIN_D1",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface BlockchainServiceEnvironmentConfig {
|
|
2
|
+
vars: {
|
|
3
|
+
RPC_URL: string;
|
|
4
|
+
};
|
|
5
|
+
d1: {
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
interface BlockchainServiceWranglerConfig {
|
|
10
|
+
project: string;
|
|
11
|
+
name: string;
|
|
12
|
+
envs: {
|
|
13
|
+
local: BlockchainServiceEnvironmentConfig;
|
|
14
|
+
[key: string]: BlockchainServiceEnvironmentConfig;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
interface BlockchainServiceEnv extends BlockchainEnv {
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type { BlockchainServiceEnvironmentConfig as B, BlockchainServiceWranglerConfig as a, BlockchainServiceEnv as b };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface BlockchainServiceEnvironmentConfig {
|
|
2
|
+
vars: {
|
|
3
|
+
RPC_URL: string;
|
|
4
|
+
};
|
|
5
|
+
d1: {
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
interface BlockchainServiceWranglerConfig {
|
|
10
|
+
project: string;
|
|
11
|
+
name: string;
|
|
12
|
+
envs: {
|
|
13
|
+
local: BlockchainServiceEnvironmentConfig;
|
|
14
|
+
[key: string]: BlockchainServiceEnvironmentConfig;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
interface BlockchainServiceEnv extends BlockchainEnv {
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type { BlockchainServiceEnvironmentConfig as B, BlockchainServiceWranglerConfig as a, BlockchainServiceEnv as b };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface BlockchainServiceEnvironmentConfig {
|
|
2
|
+
vars: {
|
|
3
|
+
RPC_URL: string;
|
|
4
|
+
};
|
|
5
|
+
d1: {
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
interface BlockchainServiceWranglerConfig {
|
|
10
|
+
project: string;
|
|
11
|
+
name: string;
|
|
12
|
+
envs: {
|
|
13
|
+
local: BlockchainServiceEnvironmentConfig;
|
|
14
|
+
[key: string]: BlockchainServiceEnvironmentConfig;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
interface BlockchainServiceEnv extends BlockchainEnv {
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type { BlockchainServiceEnvironmentConfig as B, BlockchainServiceWranglerConfig as a, BlockchainServiceEnv as b };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const syncAddressInputSchema = z.object({
|
|
4
|
+
addressId: z.string()
|
|
5
|
+
});
|
|
6
|
+
const syncAddressOutputSchema = z.object({
|
|
7
|
+
// instanceId: z.string(),
|
|
8
|
+
// details: workflowInstanceStatusSchema,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export { syncAddressOutputSchema as a, syncAddressInputSchema as s };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const syncAddressInputSchema: z.ZodObject<{
|
|
4
|
+
addressId: z.ZodString;
|
|
5
|
+
}, z.core.$strip>;
|
|
6
|
+
declare const syncAddressOutputSchema: z.ZodObject<{}, z.core.$strip>;
|
|
7
|
+
interface SyncAddressInput extends z.infer<typeof syncAddressInputSchema> {
|
|
8
|
+
}
|
|
9
|
+
type SyncAddressOutput = z.infer<typeof syncAddressOutputSchema>;
|
|
10
|
+
|
|
11
|
+
export { syncAddressOutputSchema as a, syncAddressInputSchema as s };
|
|
12
|
+
export type { SyncAddressInput as S, SyncAddressOutput as b };
|