6-PYTHON-API: Get feed creation with push working again
This commit is contained in:
parent
e8b840a608
commit
670c5124b3
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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={
|
||||
|
|
|
@ -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')
|
||||
|
||||
print(f'Feed info at: https://switchboard.xyz/explorer/2/{aggregator.public_key}')
|
Loading…
Reference in New Issue