package Ġio . pl as mas im ulator . ethereum . contracts Ċ Ċ import Ġio . pl as mas im ulator . ethereum . models . Account Ċ import Ġio . pl as mas im ulator . ethereum . models . ETH Transaction Ċ import Ġio . pl as mas im ulator . utils . Hash Utils Ċ import Ġio . vertx . core . json . Json Ċ import Ġio . vertx . core . json . JsonObject Ċ import Ġorg . slf 4 j . LoggerFactory Ċ Ċ class ĠPl asma Contract ( val Ġpl asma Block Interval : ĠInt ) Ġ{ ĊĠ Ġvar Ġstate : ĠMutable Map < String , ĠAccount > Ġ= Ġmutable Map Of () ĊĠ Ġvar Ġpl asma Block Number Ġ= Ġ 0 ĊĠ Ġvar Ġdeposit Block Number Ġ= Ġ 1 ĊĠ Ġvar Ġchild Blocks Ġ= Ġmutable Map Of < Int , ĠPl asma Block >() ĊĊĠ Ġinit Ġ{ ĊĠĠĠĠĠ Ġchild Blocks . put ( 0 , ĠPl asma Block ( Hash Utils . transform ( Hash Utils . hash (" 0 ,- 1 ". toByteArray ())) )) ĊĠĠĠĠĠ Ġpl asma Block Number Ġ= Ġpl asma Block Interval ĊĠ Ġ} ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠ Ġprivate Ġval ĠLOG Ġ= ĠLoggerFactory . getLogger ( Pl asma Contract :: class . java ) ĊĠ Ġ} ĊĊĠ Ġfun Ġdeposit ( address : ĠString , Ġamount : ĠInt , Ġchain Address : ĠString ) Ġ: ĠJsonObject { ĊĠĠĠ ĠLOG . info (" Deposit Ġ$ amount Ġfor Ġ$ address ") ĊĠĠĠ Ġstate . put ( address , ĠAccount ( 0 , Ġaddress , Ġamount )) ĊĠĠĠ Ġval Ġroot Hash Ġ= ĠHash Utils . transform ( Hash Utils . hash ( address . toByteArray () Ġ+ Ġamount . to Byte ())) ĊĠĠĠ Ġchild Blocks . put ( deposit Block Number , ĠPl asma Block ( root Hash )) ĊĠĠĠ Ġreturn ĠJsonObject () ĊĠĠĠĠĠ Ġ. put (" address ", Ġaddress ) ĊĠĠĠĠĠ Ġ. put (" amount ", Ġamount ) ĊĠĠĠĠĠ Ġ. put (" block Num ", Ġdeposit Block Number ++) ĊĠĠĠĠĠ Ġ. put (" root Hash ", Ġroot Hash ) ĊĠĠĠĠĠ Ġ. put (" chain Address ", Ġchain Address ) ĊĠ Ġ} ĊĊĠ Ġfun Ġwithdraw ( address : ĠString , Ġamount : ĠInt , Ġchain Address : ĠString ) Ġ: ĠJsonObject Ġ{ ĊĠĠĠ ĠLOG . info (" Start Ġwithdraw ing Ġfor Ġ$ address ") ĊĠĠĠ Ġvar Ġaccount Ġ= Ġstate . get ( address ) ĊĠĠĠ Ġif ( account Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠ Ġaccount . balance Ġ= Ġamount ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn ĠJsonObject () ĊĠ Ġ} ĊĊĠ Ġfun Ġsubmit Block ( root Hash : ĠString , Ġtimestamp : ĠLong ) Ġ{ ĊĠĠĠ Ġchild Blocks . put ( pl asma Block Number , ĠPl asma Block ( root Hash , Ġtimestamp )) ĊĠĠĠ Ġupdate Block Numbers () ĊĠ Ġ} ĊĊĠ Ġfun Ġupdate Block Numbers () Ġ{ ĊĠĠĠ Ġpl asma Block Number Ġ+= Ġpl asma Block Interval ĊĠĠĠ Ġdeposit Block Number Ġ= Ġpl asma Block Number Ġ+ Ġ 1 ĊĠ Ġ} Ċ } Ċ Ċ class ĠPl asma Block ( var Ġroot Hash : ĠString , Ġval Ġtimestamp : ĠLong Ġ= ĠSystem . currentTimeMillis ()) Ġ{ Ċ } Ċ