Skip to content

Commit

Permalink
add dump method
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin committed Sep 7, 2022
1 parent f3924bd commit 2189711
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 5 deletions.
16 changes: 16 additions & 0 deletions beaker/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,19 @@ def initialize_account_state(self, addr=Txn.sender()) -> Expr:
@create
def create(self) -> Expr:
return Approve()

def dump(self, directory: str = '.'):
import json
import os.path

with open(os.path.join(directory, 'approval.teal'), "w") as f:
f.write(self.approval_program)

with open(os.path.join(directory, 'clear.teal'), "w") as f:
f.write(self.clear_program)

with open(os.path.join(directory, 'contract.json'), "w") as f:
f.write(json.dumps(self.contract.dictify()))

with open(os.path.join(directory, f"{self.__class__.__name__}.json"), "w") as f:
f.write(json.dumps(self.contract.dictify()))
1 change: 1 addition & 0 deletions examples/wormhole/OracleDataCache.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name": "OracleDataCache", "methods": [{"name": "lookup", "args": [{"type": "uint64", "name": "ts"}], "returns": {"type": "(uint64,uint64,uint64)"}}, {"name": "portal_transfer", "args": [{"type": "byte[]", "name": "vaa", "desc": "VAA encoded dynamic byte array"}], "returns": {"type": "byte[]", "desc": "Undefined byte array"}, "desc": "portal_transfer accepts a VAA containing information about the transfer and the payload."}], "networks": {}, "desc": "\n Stores price feed in application state keyed by timestamp\n\n TODO: more than 64 vals lol\n "}
203 changes: 203 additions & 0 deletions examples/wormhole/approval.teal
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
#pragma version 7
intcblock 0 1
bytecblock 0x151f7c75
txn NumAppArgs
intc_0 // 0
==
bnz main_l6
txna ApplicationArgs 0
pushbytes 0x1c18e2e8 // "lookup(uint64)(uint64,uint64,uint64)"
==
bnz main_l5
txna ApplicationArgs 0
pushbytes 0x903f4535 // "portal_transfer(byte[])byte[]"
==
bnz main_l4
err
main_l4:
txn OnCompletion
intc_0 // NoOp
==
txn ApplicationID
intc_0 // 0
!=
&&
assert
txna ApplicationArgs 1
callsub portaltransfer_2
store 4
bytec_0 // 0x151f7c75
load 4
concat
log
intc_1 // 1
return
main_l5:
txn OnCompletion
intc_0 // NoOp
==
txn ApplicationID
intc_0 // 0
!=
&&
assert
txna ApplicationArgs 1
btoi
callsub lookup_1
store 0
bytec_0 // 0x151f7c75
load 0
concat
log
intc_1 // 1
return
main_l6:
txn OnCompletion
intc_0 // NoOp
==
bnz main_l8
err
main_l8:
txn ApplicationID
intc_0 // 0
==
assert
callsub create_0
intc_1 // 1
return

// create
create_0:
intc_1 // 1
return

// lookup
lookup_1:
store 1
intc_0 // 0
load 1
itob
app_global_get_ex
store 3
store 2
load 3
assert
load 2
retsub

// portal_transfer
portaltransfer_2:
store 5
load 5
extract 2 0
intc_0 // 0
getbyte
store 6
load 5
extract 2 0
intc_1 // 1
extract_uint32
store 7
load 5
extract 2 0
pushint 5 // 5
getbyte
store 8
load 5
extract 2 0
pushint 6 // 6
load 8
pushint 66 // 66
*
+
dig 1
len
substring3
store 23
load 23
intc_0 // 0
extract_uint32
store 9
load 23
pushint 4 // 4
extract_uint32
store 10
load 23
pushint 8 // 8
extract_uint16
store 11
load 23
extract 10 32
store 12
load 23
pushint 42 // 42
extract_uint64
store 13
load 23
pushint 50 // 50
getbyte
store 14
load 23
pushint 51 // 51
getbyte
store 15
load 23
extract 52 32
store 16
load 23
extract 84 32
store 17
load 23
pushint 116 // 116
extract_uint16
store 18
load 23
extract 118 32
store 19
load 23
pushint 150 // 150
extract_uint16
store 20
load 23
extract 152 32
store 21
load 23
extract 184 0
store 22
load 22
len
itob
extract 6 0
load 22
concat
store 22
load 22
extract 2 0
store 24
load 24
pushbytes 0x7473 // "ts"
json_ref JSONUint64
store 25
load 24
pushbytes 0x7072696365 // "price"
json_ref JSONUint64
store 26
load 24
pushbytes 0x636f6e666964656e6365 // "confidence"
json_ref JSONUint64
store 27
load 25
itob
load 26
itob
concat
load 27
itob
concat
store 28
load 25
itob
load 28
app_global_put
load 22
retsub
3 changes: 3 additions & 0 deletions examples/wormhole/clear.teal
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma version 7
pushint 0 // 0
return
1 change: 1 addition & 0 deletions examples/wormhole/contract.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name": "OracleDataCache", "methods": [{"name": "lookup", "args": [{"type": "uint64", "name": "ts"}], "returns": {"type": "(uint64,uint64,uint64)"}}, {"name": "portal_transfer", "args": [{"type": "byte[]", "name": "vaa", "desc": "VAA encoded dynamic byte array"}], "returns": {"type": "byte[]", "desc": "Undefined byte array"}, "desc": "portal_transfer accepts a VAA containing information about the transfer and the payload."}], "networks": {}, "desc": "\n Stores price feed in application state keyed by timestamp\n\n TODO: more than 64 vals lol\n "}
3 changes: 3 additions & 0 deletions examples/wormhole/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ def handle_transfer(
@external
def lookup(self, ts: abi.Uint64, *, output: OracleData):
return output.decode(self.prices[ts].get_must())

if __name__=="__main__":
OracleDataCache().dump()
18 changes: 13 additions & 5 deletions examples/wormhole/wormhole.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,13 @@ class WormholeTransfer(Application, ABC):
def portal_transfer(
self, vaa: abi.DynamicBytes, *, output: abi.DynamicBytes
) -> Expr:
"""
portal_transfer accepts a VAA containing information about the transfer and the payload.
""" portal_transfer accepts a VAA containing information about the transfer and the payload.
Args:
vaa: VAA encoded dynamic byte array
Returns:
Undefined byte array
To allow a more flexible interface we publicize that we output generic bytes
"""
Expand All @@ -142,10 +147,13 @@ def portal_transfer(
def handle_transfer(
self, ctvaa: ContractTransferVAA, *, output: abi.DynamicBytes
) -> Expr:
"""
Should be overridden with whatever app specific stuff
"""handle transfer should be overridden with app specific logic
needs to be done on transfer
Args:
ctvaa: The decoded ContractTransferVAA
Returns:
app specific byte array
"""
return Reject()

0 comments on commit 2189711

Please sign in to comment.