This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
forked from Flax-Network/flax-blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
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
03079a5
commit 5b49033
Showing
10 changed files
with
285 additions
and
12 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
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
Empty file.
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,5 @@ | ||
from flax.util.ints import uint64 | ||
|
||
constants = { | ||
"POOL_SUB_SLOT_ITERS": uint64(36718720) | ||
} |
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,24 @@ | ||
from dataclasses import dataclass | ||
|
||
from blspy import G2Element | ||
from flax.types.blockchain_format.proof_of_space import ProofOfSpace | ||
from flax.types.blockchain_format.sized_bytes import bytes32 | ||
from flax.util.ints import uint64 | ||
from flax.util.streamable import streamable, Streamable | ||
|
||
|
||
@dataclass(frozen=True) | ||
@streamable | ||
class PartialPayload(Streamable): | ||
proof_of_space: ProofOfSpace | ||
sp_hash: bytes32 | ||
end_of_sub_slot: bool | ||
payout_address: str # The farmer can choose where to send the rewards. This can take a few minutes | ||
|
||
|
||
@dataclass(frozen=True) | ||
@streamable | ||
class SubmitPartial(Streamable): | ||
payload: PartialPayload | ||
partial_aggregate_signature: G2Element # Sig of partial by plot key and pool key | ||
difficulty: uint64 |
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,12 @@ | ||
import time | ||
|
||
from flax.util.ints import uint64 | ||
|
||
|
||
class OgPoolState: | ||
difficulty: uint64 | ||
last_partial_submit_timestamp: float | ||
|
||
def __init__(self, difficulty: uint64 = 1, last_partial_submit_timestamp: float = time.time()): | ||
self.difficulty = difficulty | ||
self.last_partial_submit_timestamp = last_partial_submit_timestamp |
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,29 @@ | ||
from aiohttp import ClientSession, ClientTimeout | ||
|
||
from flax.farmer.pooling.og_pool_protocol import SubmitPartial | ||
from flax.server.server import ssl_context_for_root | ||
from flax.ssl.create_ssl import get_mozilla_ca_crt | ||
|
||
timeout = ClientTimeout(total=30) | ||
|
||
|
||
class PoolApiClient: | ||
base_url: str | ||
|
||
def __init__(self, base_url: str) -> None: | ||
self.base_url = base_url | ||
self.ssl_context = ssl_context_for_root(get_mozilla_ca_crt()) | ||
|
||
async def get_pool_info(self): | ||
async with ClientSession(timeout=timeout) as client: | ||
async with client.get(f"{self.base_url}/pool_info", ssl=self.ssl_context) as res: | ||
return await res.json() | ||
|
||
async def submit_partial(self, submit_partial: SubmitPartial): | ||
async with ClientSession(timeout=timeout) as client: | ||
async with client.post( | ||
f"{self.base_url}/partial", | ||
json=submit_partial.to_json_dict(), | ||
ssl=self.ssl_context | ||
) as res: | ||
return await res.json() |
Oops, something went wrong.