diff --git a/libraries/py/switchboardpy/common.py b/libraries/py/switchboardpy/common.py index fcae747..8c525b2 100644 --- a/libraries/py/switchboardpy/common.py +++ b/libraries/py/switchboardpy/common.py @@ -1,11 +1,15 @@ +import io +import six import anchorpy - from dataclasses import dataclass from functools import reduce -from typing import Any +from typing import Any, Type from decimal import Decimal from solana.publickey import PublicKey from solana.keypair import Keypair +from google.protobuf.internal import decoder +from switchboardpy.compiled import OracleJob + # Devnet Program ID. SBV2_DEVNET_PID = PublicKey( @@ -17,6 +21,49 @@ SBV2_MAINNET_PID = PublicKey( 'SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f' ) +# https://stackoverflow.com/a/34539706 +def readRawVarint32(stream: io.BytesIO): + mask = 0x80 # (1 << 7) + raw_varint32 = [] + while 1: + b = stream.read(1) + #eof + if b == "": + break + raw_varint32.append(b) + if not (ord(b) & mask): + #we found a byte starting with a 0, which means it's the last byte of this varint + break + return raw_varint32 + +def getSize(raw_varint32): + result = 0 + shift = 0 + b = six.indexbytes(raw_varint32, 0) + result |= ((ord(b) & 0x7f) << shift) + return result + +def readDelimitedFrom(MessageType: Type[OracleJob], stream: io.BytesIO): + raw_varint32 = readRawVarint32(stream) + message = None + if raw_varint32: + size = getSize(raw_varint32) + + data = stream.read(size) + if len(data) < size: + raise Exception("Unexpected end of file") + + message = MessageType() + message.ParseFromString(data) + + return message + +# take OracleJob data and return bytes +def parseOracleJob(data: bytes): + dataStream = io.BytesIO(data) + return readDelimitedFrom(OracleJob, dataStream); + + # Input parameters for constructing wrapped representations of Switchboard accounts. @dataclass diff --git a/libraries/py/switchboardpy/lease.py b/libraries/py/switchboardpy/lease.py index ee996e0..e45f5ac 100644 --- a/libraries/py/switchboardpy/lease.py +++ b/libraries/py/switchboardpy/lease.py @@ -168,7 +168,6 @@ class LeaseAccount: job_account_data = await params.aggregator_account.load_jobs() aggregator_account_data = await params.aggregator_account.load_data() job_pubkeys: list[PublicKey] = aggregator_account_data.job_pubkeys_data[:aggregator_account_data.job_pubkeys_size] - print(job_pubkeys) job_wallets: list[PublicKey] = [] wallet_bumps: list[int] = [] for job in job_account_data: @@ -208,7 +207,7 @@ class LeaseAccount: "mint": switch_token_mint.pubkey }, signers=[params.funder_authority], - remaining_accounts=[AccountMeta(is_signer=False, is_writable=True, pubkey=x) for x in job_pubkeys.extend(job_wallets)] + remaining_accounts=[AccountMeta(is_signer=False, is_writable=True, pubkey=x) for x in [*job_pubkeys, *job_wallets]] ) ) return LeaseAccount(AccountParams(program=program, public_key=lease_account.public_key)) diff --git a/libraries/py/switchboardpy/oraclequeue.py b/libraries/py/switchboardpy/oraclequeue.py index b68ff03..000dcbe 100644 --- a/libraries/py/switchboardpy/oraclequeue.py +++ b/libraries/py/switchboardpy/oraclequeue.py @@ -183,7 +183,8 @@ class OracleQueueAccount: "consecutive_oracle_failure_limit": params.consecutive_oracle_failure_limit or 1000, "minimum_delay_seconds": params.minimum_delay_seconds or 5, "queue_size": params.queue_size or 0, - "unpermissioned_feeds": params.unpermissioned_feeds or False + "unpermissioned_feeds": params.unpermissioned_feeds or False, + "mint": params.mint }, ctx=anchorpy.Context( accounts={ diff --git a/libraries/py/tests/test_create_feed.py b/libraries/py/tests/test_create_feed.py index 480ec1f..3fa16aa 100644 --- a/libraries/py/tests/test_create_feed.py +++ b/libraries/py/tests/test_create_feed.py @@ -121,7 +121,7 @@ async def test_create(): 1_000_000, skip_confirmation=False ) - + # Create lease lease = await LeaseAccount.create( program=program, @@ -146,4 +146,5 @@ async def test_create(): # Add Aggregator for auto-updates await crank.push(CrankPushParams(aggregator_account=aggregator)) - print(f'Feed info at: https://api.switchboard.xyz/api/feed/{aggregator.public_key}?network=devnet') \ No newline at end of file + + print(f'Feed info at: https://switchboard.xyz/explorer/2/{aggregator.public_key}') \ No newline at end of file