Skip to content

Commit

Permalink
Merge pull request palomachain#17 from VolumeFi/features/add-schedule…
Browse files Browse the repository at this point in the history
…r-metadata

Features/add scheduler metadata
  • Loading branch information
taariq authored Nov 28, 2023
2 parents 38d917a + f8f62cc commit 1505df2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
15 changes: 9 additions & 6 deletions integration_tests/job_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from paloma_sdk.client.lcd import AsyncLCDClient
from paloma_sdk.key.mnemonic import MnemonicKey
import time


async def main():
Expand All @@ -20,7 +21,7 @@ async def main():

test1 = paloma.wallet(acc)

job_id = "test100"
job_id = "test102"
contract_address = "0x1f576F2021b6EBdF229750f54fDFd31206141E65"
abi = [
{
Expand All @@ -38,17 +39,19 @@ async def main():
"type": "function",
},
]
creator = test1.key.acc_address
signers = [test1.key.acc_address]
payload = "6057361d00000000000000000000000000000000000000000000000000000000000000ea"
chain_type = "evm"
chain_reference_id = "bnb-main"
result = await paloma.job_scheduler.create_job(
test1, job_id, contract_address, abi, payload, chain_type, chain_reference_id
test1, job_id, contract_address, abi, payload, chain_type, chain_reference_id, creator, signers
)
print(result)

job_id = "test100"
payload = "6057361d0000000000000000000000000000000000000000000000000000000000000003"
result = await paloma.job_scheduler.execute_job(test1, job_id, payload)
time.sleep(10)
job_id = "test102"
payload = "6057361d00000000000000000000000000000000000000000000000000000000000000ea"
result = await paloma.job_scheduler.execute_job(test1, job_id, payload, creator, signers)
print(result)
await paloma.session.close()

Expand Down
20 changes: 20 additions & 0 deletions paloma_sdk/client/lcd/api/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ async def create_job(
payload: str,
chain_type: str,
chain_reference_id: str,
creator: str,
signers: list[str],
) -> SyncTxBroadcastResult:
"""Create a job with data
Args:
Expand All @@ -30,6 +32,8 @@ async def create_job(
payload (str): default payload data of the job
chain_type (str): purpose chain type
chain_reference_id (str): chain reference id in paloma
creator (str): job creator
signers (list[str]): signers list
Returns:
SyncTxBroadcastResult: transaction result
"""
Expand Down Expand Up @@ -58,6 +62,10 @@ async def create_job(
"triggers": [],
"address": "",
},
{
"creator": creator,
"signers": signers,
},
)
]
)
Expand All @@ -70,12 +78,16 @@ async def execute_job(
wallet: Wallet,
job_id: str,
payload: str,
creator: str,
signers: list[str],
) -> SyncTxBroadcastResult:
"""Execute a job with data
Args:
wallet (Wallet): Job creator paloma wallet
job_id (str): Job ID
payload (str): payload data of the job on execution
creator (str): job creator
signers (list[str]): signers list
Returns:
SyncTxBroadcastResult: transaction result
"""
Expand All @@ -86,6 +98,10 @@ async def execute_job(
wallet.key.acc_address,
job_id,
json.dumps({"hexPayload": payload}, separators=[",", ":"]),
{
"creator": creator,
"signers": signers,
},
)
]
)
Expand All @@ -105,6 +121,8 @@ def create_job(
payload: str,
chain_type: str,
chain_reference_id: str,
creator: str,
signers: list[str],
) -> SyncTxBroadcastResult:
pass

Expand All @@ -114,6 +132,8 @@ def execute_job(
wallet: Wallet,
job_id: str,
payload: str,
creator: str,
signers: list[str],
) -> SyncTxBroadcastResult:
pass

Expand Down
8 changes: 8 additions & 0 deletions paloma_sdk/core/scheduler/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class Routing(betterproto.Message):
chain_reference_id: str = betterproto.string_field(2)


@dataclass(eq=False, repr=False)
class Metadata(betterproto.Message):
creator: bytes = betterproto.bytes_field(1)
signers: List[bytes] = betterproto.message_field(2)


@dataclass(eq=False, repr=False)
class Job(betterproto.Message):
id: str = betterproto.string_field(1)
Expand All @@ -56,10 +62,12 @@ class Job(betterproto.Message):
class MsgCreateJob(betterproto.Message):
creator: str = betterproto.string_field(1)
job: "Job" = betterproto.message_field(2)
metadata: "Metadata" = betterproto.message_field(3)


@dataclass(eq=False, repr=False)
class MsgExecuteJob(betterproto.Message):
creator: str = betterproto.string_field(1)
job_id: str = betterproto.string_field(2)
payload: bytes = betterproto.bytes_field(3)
metadata: "Metadata" = betterproto.message_field(4)
15 changes: 15 additions & 0 deletions paloma_sdk/core/scheduler/msgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .data import MsgExecuteJob as MsgExecuteJob_pb
from .data import Permissions as Permissions_pb
from .data import Routing as Routing_pb
from .data import Metadata as Metadata_pb
from .data import ScheduleTrigger as ScheduleTrigger_pb
from .data import Trigger as Trigger_pb

Expand Down Expand Up @@ -67,13 +68,15 @@ class MsgCreateJob(Msg):

creator: AccAddress = attr.ib()
job: Job = attr.ib()
metadata: dict = attr.ib()

def to_amino(self) -> dict:
return {
"type": self.type_amino,
"value": {
"creator": self.creator,
"job": remove_none(self.job),
"metadata": remove_none(self.metadata),
},
}

Expand All @@ -82,6 +85,7 @@ def from_data(cls, data: dict) -> MsgCreateJob:
return cls(
creator=data["creator"],
job=parse_msg(data["job"]),
metadata=parse_msg(data["metadata"]),
)

def to_proto(self) -> MsgCreateJob_pb:
Expand All @@ -104,6 +108,10 @@ def to_proto(self) -> MsgCreateJob_pb:
triggers=[Trigger_pb(schedule=ScheduleTrigger_pb())],
address=bytes(self.job["address"], "ascii"),
),
metadata=Metadata_pb(
creator=bytes(self.metadata["creator"], "ascii"),
signers=[bytes(signer, "ascii") for signer in self.metadata["signers"]],
),
)

@classmethod
Expand All @@ -130,6 +138,7 @@ class MsgExecuteJob(Msg):
creator: AccAddress = attr.ib()
job_id: str = attr.ib()
payload: str = attr.ib()
metadata: dict = attr.ib()

def to_amino(self) -> dict:
return {
Expand All @@ -138,6 +147,7 @@ def to_amino(self) -> dict:
"creator": self.creator,
"job_id": self.job_id,
"payload": self.payload,
"metadata": self.metadata,
},
}

Expand All @@ -147,13 +157,18 @@ def from_data(cls, data: dict) -> MsgExecuteJob:
creator=data["creator"],
job_id=data["job_id"],
payload=data["payload"],
metadata=parse_msg(data["metadata"]),
)

def to_proto(self) -> MsgExecuteJob_pb:
return MsgExecuteJob_pb(
creator=self.creator,
job_id=self.job_id,
payload=bytes(self.payload, "ascii"),
metadata=Metadata_pb(
creator=bytes(self.metadata["creator"], "ascii"),
signers=[bytes(signer, "ascii") for signer in self.metadata["signers"]],
),
)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ license = "MIT"
packages = [{ include = "paloma_sdk" }]
readme = "README.md"
repository = "https://github.com/palomachain/paloma.py"
version = "3.0.18"
version = "3.0.19"

[tool.poetry.dependencies]
aiohttp = "^3.8.1"
Expand Down

0 comments on commit 1505df2

Please sign in to comment.