Skip to content

Commit 337c1cc

Browse files
committed
Added setLedgerSequence step and rule to node.md
1 parent f2ab839 commit 337c1cc

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

src/komet_node/interpreter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def contract_address_from_deployer_address(self, deployer_public_key: str, salt:
157157
)
158158
return StrKey.encode_contract(self.contract_id_from_preimage(preimage))
159159

160-
def run_transaction(self, input_file: Path, transaction: Transaction) -> InterpreterResponse:
160+
def run_transaction(self, input_file: Path, transaction: Transaction, ledger_seq: int = 0) -> InterpreterResponse:
161161

162162
def operation_to_steps(op: Operation) -> list[KInner]:
163163
match op:
@@ -210,7 +210,7 @@ def operation_to_steps(op: Operation) -> list[KInner]:
210210
case _:
211211
raise NotImplementedError(f'Unsupported operation type: {type(op)}')
212212

213-
request_str = self.encode_transaction_to_json(transaction)
213+
request_str = self.encode_transaction_to_json(transaction, ledger_seq)
214214
if request_str is not None:
215215
return self.run_request_file(input_file, request_str)
216216

@@ -252,7 +252,7 @@ def make_call_tx(self, caller: MuxedAccount, invoke: xdr.InvokeContractArgs) ->
252252
)
253253
return [step]
254254

255-
def encode_transaction_to_json(self, transaction: Transaction) -> str | None:
255+
def encode_transaction_to_json(self, transaction: Transaction, ledger_seq: int = 0) -> str | None:
256256
"""
257257
Encode a transaction as a JSON request string for the fast path.
258258
@@ -262,7 +262,7 @@ def encode_transaction_to_json(self, transaction: Transaction) -> str | None:
262262
Key ordering in each step dict is significant: it must match the K JSON patterns
263263
in node.md exactly, because K's JSON sort is ordered.
264264
"""
265-
steps = []
265+
steps = [{'op': 'setLedgerSequence', 'sequence': ledger_seq}]
266266
for op in transaction.operations:
267267
encoded = self._encode_operation_as_json(op, transaction.source)
268268
if encoded is None:

src/komet_node/kdist/node.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ module NODE
3030
syntax KItem ::= "#handleRequestFile"
3131
| "#removeRequestFile"
3232
| #handleRequest(String)
33+
34+
syntax Step ::= setLedgerSequence(Int) [symbol(setLedgerSequence)]
35+
// ----------------------------------------------------------------------
36+
rule [setLedgerSequence]:
37+
<k> setLedgerSequence(SEQ) => .K ... </k>
38+
<ledgerSequenceNumber> _ => SEQ </ledgerSequenceNumber>
3339
```
3440

3541
HexBytes: decode a lowercase hex string to Bytes (big-endian, length = hex length / 2).
@@ -104,10 +110,11 @@ JSON request format (key order is significant — must match Python's json.dumps
104110

105111
where each <step> is one of:
106112

107-
{ "op": "setAccount", "account": "<hex32>", "balance": <int> }
108-
{ "op": "deployContract", "from": "<hex32>", "address": "<hex32>", "wasmHash": "<hex32>" }
109-
{ "op": "callTx", "from": "<hex32>", "fromIsContract": <bool>,
110-
"func": "<name>", "to": "<hex32>", "args": [ <scval>, ... ] }
113+
{ "op": "setLedgerSequence", "sequence": <int> }
114+
{ "op": "setAccount", "account": "<hex32>", "balance": <int> }
115+
{ "op": "deployContract", "from": "<hex32>", "address": "<hex32>", "wasmHash": "<hex32>" }
116+
{ "op": "callTx", "from": "<hex32>", "fromIsContract": <bool>,
117+
"func": "<name>", "to": "<hex32>", "args": [ <scval>, ... ] }
111118

112119
SCVal arg encoding (key order also significant):
113120

@@ -131,6 +138,9 @@ SCVal arg encoding (key order also significant):
131138
rule #decodeSteps(.JSONs) => .Steps
132139
rule #decodeSteps(S:JSON, SS:JSONs) => #decodeStep(S) #decodeSteps(SS)
133140
141+
rule #decodeStep({ "op" : "setLedgerSequence" , "sequence" : SEQ:Int })
142+
=> setLedgerSequence(SEQ)
143+
134144
rule #decodeStep({ "op" : "setAccount" , "account" : ACCT:String , "balance" : BAL:Int })
135145
=> setAccount(Account(HexBytes(ACCT)), BAL)
136146

src/komet_node/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def exec_send_transaction(self, transaction: str) -> dict[str, Any]:
7373
tx_hash = envelope.hash_hex()
7474

7575
try:
76-
result = self.interpreter.run_transaction(self.state_file, envelope.transaction)
76+
result = self.interpreter.run_transaction(self.state_file, envelope.transaction, self.ledger_seq)
7777
self.state_file.write_text(result.final_kore)
7878
self.ledger_seq += 1
7979
self._transactions[tx_hash] = {

0 commit comments

Comments
 (0)