astreum 0.2.40__py3-none-any.whl → 0.2.42__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of astreum might be problematic. Click here for more details.

astreum/models/block.py CHANGED
@@ -4,8 +4,8 @@ from threading import Thread
4
4
  from typing import List, Dict, Any, Optional, Union
5
5
 
6
6
  from astreum.crypto.wesolowski import vdf_generate, vdf_verify
7
- from astreum.models.account import Account
8
- from astreum.models.accounts import Accounts
7
+ from astreum._consensus.account import Account
8
+ from astreum._consensus.accounts import Accounts
9
9
  from astreum.models.patricia import PatriciaTrie
10
10
  from astreum.models.transaction import Transaction
11
11
  from ..crypto import ed25519
@@ -103,9 +103,9 @@ class Block:
103
103
  stake_root = stake_trie.root_hash
104
104
 
105
105
  # 2. three Account bodies
106
- validator_acct = Account.create(balance=0, data=b"", nonce=0)
107
- treasury_acct = Account.create(balance=1, data=stake_root, nonce=0)
108
- burn_acct = Account.create(balance=0, data=b"", nonce=0)
106
+ validator_acct = Account.create(balance=0, data=b"", counter=0)
107
+ treasury_acct = Account.create(balance=1, data=stake_root, counter=0)
108
+ burn_acct = Account.create(balance=0, data=b"", counter=0)
109
109
 
110
110
  # 3. global Accounts structure
111
111
  accts = Accounts()
@@ -190,7 +190,7 @@ class Block:
190
190
 
191
191
  def _credit(addr: bytes, amt: int):
192
192
  acc = blk.accounts.get_account(addr) or Account.create(0, b"", 0)
193
- blk.accounts.set_account(addr, Account.create(acc.balance() + amt, acc.data(), acc.nonce()))
193
+ blk.accounts.set_account(addr, Account.create(acc.balance + amt, acc.data, acc.counter))
194
194
 
195
195
  if burn_amt:
196
196
  _credit(BURN, burn_amt)
@@ -280,17 +280,17 @@ class Block:
280
280
 
281
281
  sender_acct = self.accounts.get_account(sender_pk)
282
282
  if (sender_acct is None
283
- or sender_acct.nonce() != nonce
284
- or sender_acct.balance() < amount + fee):
283
+ or sender_acct.counter != nonce
284
+ or sender_acct.balance < amount + fee):
285
285
  raise ValueError("invalid or unaffordable transaction")
286
286
 
287
287
  # --- debit sender --------------------------------------------------
288
288
  self.accounts.set_account(
289
289
  sender_pk,
290
290
  Account.create(
291
- balance=sender_acct.balance() - amount - fee,
292
- data=sender_acct.data(),
293
- nonce=sender_acct.nonce() + 1,
291
+ balance=sender_acct.balance - amount - fee,
292
+ data=sender_acct.data,
293
+ counter=sender_acct.counter + 1,
294
294
  )
295
295
  )
296
296
 
@@ -298,14 +298,14 @@ class Block:
298
298
  if recip_pk == TREASURY:
299
299
  treasury = self.accounts.get_account(TREASURY)
300
300
 
301
- trie = PatriciaTrie(node_get=None, root_hash=treasury.data())
301
+ trie = PatriciaTrie(node_get=None, root_hash=treasury.data)
302
302
  stake_bytes = trie.get(sender_pk) or b""
303
303
  current_stake = int.from_bytes(stake_bytes, "big") if stake_bytes else 0
304
304
 
305
305
  if amount > 0:
306
306
  # stake **deposit**
307
307
  trie.put(sender_pk, (current_stake + amount).to_bytes(32, "big"))
308
- new_treas_bal = treasury.balance() + amount
308
+ new_treas_bal = treasury.balance + amount
309
309
  else:
310
310
  # stake **withdrawal**
311
311
  if current_stake == 0:
@@ -315,13 +315,13 @@ class Block:
315
315
  self.accounts.set_account(
316
316
  sender_pk,
317
317
  Account.create(
318
- balance=sender_after.balance() + current_stake,
319
- data=sender_after.data(),
320
- nonce=sender_after.nonce(),
318
+ balance=sender_after.balance + current_stake,
319
+ data=sender_after.data,
320
+ counter=sender_after.counter,
321
321
  )
322
322
  )
323
323
  trie.delete(sender_pk)
324
- new_treas_bal = treasury.balance() # treasury balance unchanged
324
+ new_treas_bal = treasury.balance # treasury balance unchanged
325
325
 
326
326
  # write back treasury with new trie root
327
327
  self.accounts.set_account(
@@ -329,7 +329,7 @@ class Block:
329
329
  Account.create(
330
330
  balance=new_treas_bal,
331
331
  data=trie.root_hash,
332
- nonce=treasury.nonce(),
332
+ counter=treasury.counter,
333
333
  )
334
334
  )
335
335
 
@@ -338,9 +338,9 @@ class Block:
338
338
  self.accounts.set_account(
339
339
  recip_pk,
340
340
  Account.create(
341
- balance=recip_acct.balance() + amount,
342
- data=recip_acct.data(),
343
- nonce=recip_acct.nonce(),
341
+ balance=recip_acct.balance + amount,
342
+ data=recip_acct.data,
343
+ counter=recip_acct.counter,
344
344
  )
345
345
  )
346
346
 
@@ -417,7 +417,7 @@ class Block:
417
417
  v_acct = dummy.accounts.get_account(self.validator_pk) or Account.create(0,b"",0)
418
418
  dummy.accounts.set_account(
419
419
  self.validator_pk,
420
- Account.create(v_acct.balance()+rew, v_acct.data(), v_acct.nonce())
420
+ Account.create(v_acct.balance+rew, v_acct.data, v_acct.counter)
421
421
  )
422
422
 
423
423
  if dummy.accounts.root_hash != self.accounts_hash: