Package org.ethereum.facade

Examples of org.ethereum.facade.Repository


    public void test12() {

        String addr = "cd2a3d9f938e13cd947ec05abc7fe734df8dd826";
        long expectedBalance = 333;

        Repository origRepository = worldManager.getRepository();

        Repository repository = origRepository.getTrack();
        repository.startTracking();

        repository.createAccount(Hex.decode(addr));
        repository.addBalance(Hex.decode(addr), BigInteger.valueOf(expectedBalance));

        repository.commit();

        BigInteger balance =  repository.getBalance(Hex.decode(addr));

        assertEquals(expectedBalance, balance.longValue());
    }
View Full Code Here


        String addr = "cd2a3d9f938e13cd947ec05abc7fe734df8dd826";
        long expectedBalance_1 = 55500;
        long expectedBalance_2 = 0;

        Repository origRepository = worldManager.getRepository();
        Repository repository = origRepository.getTrack();
        repository.startTracking();

        repository.createAccount(Hex.decode(addr));
        repository.addBalance(Hex.decode(addr), BigInteger.valueOf(55500));

        BigInteger balance =  repository.getBalance(Hex.decode(addr));
        assertEquals(expectedBalance_1, balance.longValue());
        repository.rollback();

        balance =  repository.getBalance(Hex.decode(addr));
        assertEquals(expectedBalance_2, balance.longValue());
    }
View Full Code Here

        String addr_2 = "77045e71a7a2c50903d88e564cd72fab11e82051";
        String codeString = "7f60c860005461012c602054000000000000000000000000000000000000000000600060206000f200";

        long expectedBalance = 55500;

        Repository origRepository = worldManager.getRepository();
        Repository repository = origRepository.getTrack();

        repository.createAccount(Hex.decode(addr_1));
        repository.addBalance(Hex.decode(addr_1), BigInteger.valueOf(expectedBalance));
        repository.startTracking();

        repository.createAccount(Hex.decode(addr_2));
        repository.saveCode(Hex.decode(addr_2), Hex.decode(codeString));
        repository.addStorageRow(Hex.decode(addr_2), new DataWord(101), new DataWord(1000001));
        repository.addStorageRow(Hex.decode(addr_2), new DataWord(102), new DataWord(1000002));
        repository.addStorageRow(Hex.decode(addr_2), new DataWord(103), new DataWord(1000003));
        repository.rollback();

        BigInteger balance =  repository.getBalance(Hex.decode(addr_1));
        assertEquals(expectedBalance, balance.longValue());

        DataWord value = repository.getStorageValue(Hex.decode(addr_2), new DataWord(101));
        assertNull(value);
    }
View Full Code Here

  private void loadAccounts() {
    new Thread(){
     
      @Override
      public void run(){
                Repository repository = UIEthereumManager.ethereum.getRepository();
        DBIterator i = repository.getAccountsIterator();
        while(i.hasNext()) {
          DataClass dc = new DataClass();
          dc.address = i.next().getKey();
         
          AccountState state = repository.getAccountState(dc.address);
          dc.accountState = state;
         
          adapter.addDataPiece(dc);
        }
      }
View Full Code Here

            return;
        }
        result.getRepository().addBalance(senderAddress, endowment.negate());
        BigInteger newBalance = result.getRepository().addBalance(newAddress, endowment);

        Repository trackRepository = result.getRepository().getTrack();
        trackRepository.startTracking();
       
        // [3] UPDATE THE NONCE
        // (THIS STAGE IS NOT REVERTED BY ANY EXCEPTION)
        trackRepository.increaseNonce(senderAddress);

        // [5] COOK THE INVOKE AND EXECUTE
    ProgramInvoke programInvoke = ProgramInvokeFactory.createProgramInvoke(
        this, new DataWord(newAddress), DataWord.ZERO, gasLimit,
        newBalance, null, trackRepository);
   
        ProgramResult result = null;
       
        if (programCode != null && programCode.length != 0) {
            VM vm = new VM();
            Program program = new Program(programCode, programInvoke);
            vm.play(program);
            result = program.getResult();
            this.result.addDeleteAccounts(result.getDeleteAccounts());
        }
       
        if (result != null &&
            result.getException() != null &&
                result.getException() instanceof Program.OutOfGasException) {
            logger.info("contract run halted by OutOfGas: new contract init ={}" , Hex.toHexString(newAddress));

            trackRepository.rollback();
            stackPushZero();
            return;
        }

        // 4. CREATE THE CONTRACT OUT OF RETURN
        byte[] code    = result.getHReturn().array();
        trackRepository.saveCode(newAddress, code);
        trackRepository.commit();
       
        // IN SUCCESS PUSH THE ADDRESS INTO THE STACK
        stackPush(new DataWord(newAddress));
       
        // 5. REFUND THE REMAIN GAS
View Full Code Here

        }
       
        //  actual gas subtract
        this.spendGas(msg.getGas().longValue(), "internal call");
       
        Repository trackRepository = result.getRepository().getTrack();
        trackRepository.startTracking();

    ProgramInvoke programInvoke = ProgramInvokeFactory.createProgramInvoke(
        this, new DataWord(contextAddress), msg.getEndowment(),
        msg.getGas(), contextBalance, data, trackRepository);
   
        ProgramResult result = null;

        if (programCode != null && programCode.length != 0) {
            VM vm = new VM();
            Program program = new Program(programCode, programInvoke);
            vm.play(program);
            result = program.getResult();
            this.getProgramTrace().merge(program.getProgramTrace());
            this.result.addDeleteAccounts(result.getDeleteAccounts());
        }
       
        if (result != null &&
              result.getException() != null &&
              result.getException() instanceof Program.OutOfGasException) {
            gasLogger.info("contract run halted by OutOfGas: contract={}" , Hex.toHexString(contextAddress));

            trackRepository.rollback();
            stackPushZero();
            return;
        }

        // 3. APPLY RESULTS: result.getHReturn() into out_memory allocated
        if (result != null) {
            ByteBuffer buffer = result.getHReturn();
            int allocSize = msg.getOutDataSize().intValue();
            if (buffer != null && allocSize > 0) {
                int retSize = buffer.limit();
                int offset = msg.getOutDataOffs().intValue();
                if (retSize > allocSize)
                    this.memorySave(offset, buffer.array());
                else
                    this.memorySave(offset, allocSize, buffer.array());
            }
        }
       
        // 4. THE FLAG OF SUCCESS IS ONE PUSHED INTO THE STACK
        trackRepository.commit();
        stackPushOne();
       
        // 5. REFUND THE REMAIN GAS
        if (result != null) {
            BigInteger refundGas = msg.getGas().value().subtract(BigInteger.valueOf(result.getGasUsed()));
View Full Code Here


    @Test   // Testing account for simple balance set
    public void accountTest_1(){

        Repository repository = worldManager.getRepository();

        ECKey cowKey = ECKey.fromPrivate(HashUtil.sha3("cow".getBytes()));
        repository.createAccount(cowKey.getAddress());
        repository.addBalance(cowKey.getAddress(), BigInteger.TEN);

        Wallet wallet = new Wallet();
        wallet.setWorldManager(worldManager);

        wallet.importKey(cowKey.getPrivKeyBytes());
View Full Code Here


    @Test  // test account balance with pending "unblocked" transaction
    public void accountTest_2(){

        Repository repository = worldManager.getRepository();

        ECKey cowKey = ECKey.fromPrivate(HashUtil.sha3("cow".getBytes()));
        repository.createAccount(cowKey.getAddress());
        repository.addBalance(cowKey.getAddress(), BigInteger.TEN);

        Wallet wallet = new Wallet();
        wallet.setWorldManager(worldManager);

        wallet.importKey(cowKey.getPrivKeyBytes());
View Full Code Here

    // CREATE AND/OR EXECUTE CONTRACT
    long gasUsed = 0;
    if (isContractCreation || code != null) {
 
      // START TRACKING FOR REVERT CHANGES OPTION
      Repository trackRepository = repository.getTrack();
      trackRepository.startTracking();
      try {
       
        // CREATE NEW CONTRACT ADDRESS AND ADD TX VALUE
        if(isContractCreation) {
          if (isValueTx) // adding to balance also creates the account
            trackRepository.addBalance(receiverAddress, new BigInteger(1, tx.getValue()));
          else
            trackRepository.createAccount(receiverAddress);
         
          if(stateLogger.isDebugEnabled())
            stateLogger.debug("new contract created address={}",
                Hex.toHexString(receiverAddress));
        }
       
        Block currBlock =  (block == null) ? this.getBestBlock() : block;

        ProgramInvoke programInvoke =
                        programInvokeFactory.createProgramInvoke(tx, currBlock, trackRepository);
       
        VM vm = new VM();
        Program program = new Program(code, programInvoke);

                if (CONFIG.playVM())
            vm.play(program);

                program.saveProgramTraceToFile(Hex.toHexString(tx.getHash()));
        ProgramResult result = program.getResult();
        applyProgramResult(result, gasDebit, gasPrice, trackRepository,
            senderAddress, receiverAddress, coinbase, isContractCreation);
        gasUsed = result.getGasUsed();

      } catch (RuntimeException e) {
        trackRepository.rollback();
        return new BigInteger(1, tx.getGasLimit()).longValue();
      }
      trackRepository.commit();
    } else {
      // REFUND GASDEBIT EXCEPT FOR FEE (500 + 5*TXDATA)
      long dataCost = tx.getData() == null ? 0: tx.getData().length * GasCost.TXDATA;
      gasUsed = GasCost.TRANSACTION + dataCost;
     
View Full Code Here

TOP

Related Classes of org.ethereum.facade.Repository

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.