Skip to content

Commit 2e8b3d3

Browse files
committed
database schema and example block fetching
1 parent 43eedce commit 2e8b3d3

File tree

1 file changed

+33
-2
lines changed
  • scraper_service/shovel_alpha_to_tao

1 file changed

+33
-2
lines changed

scraper_service/shovel_alpha_to_tao/main.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def do_process_block(self, n):
3131
block_number UInt64 CODEC(Delta, ZSTD),
3232
timestamp DateTime CODEC(Delta, ZSTD),
3333
netuid UInt8 CODEC(Delta, ZSTD),
34-
alpha Float64 CODEC(ZSTD)
34+
alpha_to_tao Float64 CODEC(ZSTD)
3535
) ENGINE = ReplacingMergeTree()
3636
PARTITION BY toYYYYMM(timestamp)
3737
ORDER BY (block_number, netuid)
@@ -57,7 +57,38 @@ def do_process_block(self, n):
5757
raise ShovelProcessingError(f"Invalid block timestamp (0) for block {n}")
5858

5959
try:
60-
buffer_insert(self.table_name, [n, block_timestamp])
60+
# Get list of active subnets
61+
networks_added = substrate.query_map(
62+
'SubtensorModule',
63+
'NetworksAdded',
64+
block_hash=block_hash
65+
)
66+
networks = [int(net[0].value) for net in networks_added]
67+
68+
# Process each subnet
69+
for netuid in networks:
70+
subnet_tao = float(str(substrate.query(
71+
'SubtensorModule',
72+
'SubnetTAO',
73+
[netuid],
74+
block_hash=block_hash
75+
).value).replace(',', '')) / 1e9
76+
77+
subnet_alpha_in = float(str(substrate.query(
78+
'SubtensorModule',
79+
'SubnetAlphaIn',
80+
[netuid],
81+
block_hash=block_hash
82+
).value).replace(',', '')) / 1e9
83+
84+
# Calculate exchange rate (TAO per Alpha)
85+
alpha_to_tao = subnet_tao / subnet_alpha_in if subnet_alpha_in > 0 else 0
86+
87+
buffer_insert(
88+
self.table_name,
89+
[n, block_timestamp, netuid, alpha_to_tao]
90+
)
91+
6192
except Exception as e:
6293
raise DatabaseConnectionError(f"Failed to insert data into buffer: {str(e)}")
6394

0 commit comments

Comments
 (0)