1- import { Ledger , Test , initializeBindings } from '../../../bindings.js' ;
2- import { Types , TypesBigint } from '../../../bindings/mina-transaction/v1/types.js' ;
1+ import { Test , initializeBindings } from '../../../bindings.js' ;
2+ import { TypesBigint } from '../../../bindings/mina-transaction/v1/types.js' ;
33import { transactionCommitments } from '../../../mina-signer/src/sign-zkapp-command.js' ;
44import { NetworkId } from '../../../mina-signer/src/types.js' ;
5- import { Ml } from '../../ml/conversion.js' ;
65import { PrivateKey , PublicKey } from '../../provable/crypto/signature.js' ;
76import { UInt32 , UInt64 } from '../../provable/int.js' ;
87import { Field } from '../../provable/wrapped.js' ;
9- import { prettifyStacktrace } from '../../util/errors.js' ;
108import { TupleN } from '../../util/types.js' ;
119import { Actions , Authorization , TokenId , ZkappCommand } from './account-update.js' ;
1210import { Account } from './account.js' ;
1311import { invalidTransactionError } from './errors.js' ;
12+ import { LocalLedger } from './ledger/ledger.js' ;
1413import {
1514 Mina ,
1615 defaultNetworkConstants ,
@@ -71,24 +70,16 @@ async function LocalBlockchain({ proofsEnabled = true, enforceTransactionLimits
7170 const slotTime = 3 * 60 * 1000 ;
7271 const startTime = Date . now ( ) ;
7372 const genesisTimestamp = UInt64 . from ( startTime ) ;
74- const ledger = Ledger . create ( ) ;
73+ const ledger = LocalLedger . create ( ) ;
7574 let networkState = defaultNetworkState ( ) ;
7675
77- function addAccount ( publicKey : PublicKey , balance : string ) {
78- try {
79- ledger . addAccount ( Ml . fromPublicKey ( publicKey ) , balance ) ;
80- } catch ( error ) {
81- throw prettifyStacktrace ( error ) ;
82- }
83- }
84-
8576 let testAccounts = [ ] as never as TupleN < TestPublicKey , 10 > ;
8677
8778 for ( let i = 0 ; i < 10 ; ++ i ) {
8879 let MINA = 10n ** 9n ;
8980 const largeValue = 1000n * MINA ;
9081 const testAccount = TestPublicKey . random ( ) ;
91- addAccount ( testAccount , largeValue . toString ( ) ) ;
82+ ledger . addAccount ( testAccount , largeValue . toString ( ) ) ;
9283 testAccounts . push ( testAccount ) ;
9384 }
9485
@@ -109,14 +100,14 @@ async function LocalBlockchain({ proofsEnabled = true, enforceTransactionLimits
109100 return UInt32 . from ( Math . ceil ( ( new Date ( ) . valueOf ( ) - startTime ) / slotTime ) ) ;
110101 } ,
111102 hasAccount ( publicKey : PublicKey , tokenId : Field = TokenId . default ) {
112- return ! ! ledger . getAccount ( Ml . fromPublicKey ( publicKey ) , Ml . constFromField ( tokenId ) ) ;
103+ return ! ! ledger . getAccount ( publicKey , tokenId ) ;
113104 } ,
114105 getAccount ( publicKey : PublicKey , tokenId : Field = TokenId . default ) : Account {
115- let accountJson = ledger . getAccount ( Ml . fromPublicKey ( publicKey ) , Ml . constFromField ( tokenId ) ) ;
116- if ( accountJson === undefined ) {
106+ const account = ledger . getAccount ( publicKey , tokenId ) ;
107+ if ( account === undefined ) {
117108 throw new Error ( reportGetAccountError ( publicKey . toBase58 ( ) , TokenId . toBase58 ( tokenId ) ) ) ;
118109 }
119- return Types . Account . fromJSON ( accountJson ) ;
110+ return account ;
120111 } ,
121112 getNetworkState ( ) {
122113 return networkState ;
@@ -137,7 +128,7 @@ async function LocalBlockchain({ proofsEnabled = true, enforceTransactionLimits
137128 for ( const update of txn . transaction . accountUpdates ) {
138129 let authIsProof = ! ! update . authorization . proof ;
139130 let kindIsProof = update . body . authorizationKind . isProved . toBoolean ( ) ;
140- // checks and edge case where a proof is expected, but the developer forgot to invoke await tx.prove()
131+ // checks an edge case where a proof is expected, but the developer forgot to invoke await tx.prove()
141132 // this resulted in an assertion OCaml error, which didn't contain any useful information
142133 if ( kindIsProof && ! authIsProof ) {
143134 throw Error (
@@ -149,12 +140,8 @@ async function LocalBlockchain({ proofsEnabled = true, enforceTransactionLimits
149140
150141 // the first time we encounter an account, use it from the persistent ledger
151142 if ( account === undefined ) {
152- let accountJson = ledger . getAccount (
153- Ml . fromPublicKey ( update . body . publicKey ) ,
154- Ml . constFromField ( update . body . tokenId )
155- ) ;
156- if ( accountJson !== undefined ) {
157- let storedAccount = Account . fromJSON ( accountJson ) ;
143+ let storedAccount = ledger . getAccount ( update . body . publicKey , update . body . tokenId ) ;
144+ if ( storedAccount !== undefined ) {
158145 simpleLedger . store ( storedAccount ) ;
159146 account = storedAccount ;
160147 }
@@ -178,10 +165,10 @@ async function LocalBlockchain({ proofsEnabled = true, enforceTransactionLimits
178165 let status : PendingTransactionStatus = 'pending' ;
179166 const errors : string [ ] = [ ] ;
180167 try {
181- ledger . applyJsonTransaction (
182- JSON . stringify ( zkappCommandJson ) ,
183- defaultNetworkConstants . accountCreationFee . toString ( ) ,
184- JSON . stringify ( networkState )
168+ ledger . applyTransaction (
169+ txn . transaction ,
170+ defaultNetworkConstants . accountCreationFee ,
171+ networkState
185172 ) ;
186173 } catch ( err : any ) {
187174 status = 'rejected' ;
@@ -310,13 +297,6 @@ async function LocalBlockchain({ proofsEnabled = true, enforceTransactionLimits
310297 } ) ;
311298 } ) ;
312299 } ,
313- applyJsonTransaction ( json : string ) {
314- return ledger . applyJsonTransaction (
315- json ,
316- defaultNetworkConstants . accountCreationFee . toString ( ) ,
317- JSON . stringify ( networkState )
318- ) ;
319- } ,
320300 async fetchEvents ( publicKey : PublicKey , tokenId : Field = TokenId . default ) {
321301 // Return events in reverse chronological order (latest events at the beginning)
322302 const reversedEvents = (
@@ -363,7 +343,7 @@ async function LocalBlockchain({ proofsEnabled = true, enforceTransactionLimits
363343 }
364344 return currentActions . slice ( startIndex , endIndex ) ;
365345 } ,
366- addAccount,
346+ addAccount : ledger . addAccount . bind ( ledger ) ,
367347 /**
368348 * An array of 10 test accounts that have been pre-filled with
369349 * 30000000000 units of currency.
0 commit comments