Class ServiceManager


  • public abstract class ServiceManager
    extends java.lang.Object
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  ServiceManager.Block  
    • Constructor Summary

      Constructors 
      Constructor Description
      ServiceManager()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract java.lang.Object call​(Account from, java.math.BigInteger value, Address targetAddress, java.lang.String method, java.lang.Object... params)
      Call specified method.
      abstract <T> T call​(java.lang.Class<T> cls, Address targetAddress, java.lang.String method, java.lang.Object... params)
      Call specified method for read.
      abstract java.lang.Object call​(Address targetAddress, java.lang.String method, java.lang.Object... params)
      Call specified method for read.
      abstract Account createAccount()
      Create new EoA account.
      abstract Account createAccount​(int initialIcx)
      Create new EoA account with specified balance.
      abstract Account createScoreAccount()
      Create new dummy smart contract account.
      abstract Score deploy​(Account caller, java.lang.Class<?> mainClass, java.lang.Object... params)
      Deploy contract
      abstract Score deploy​(Address addr, Account owner, java.lang.Object instance)
      Deploy SCORE on specified address.
      abstract Account getAccount​(Address addr)
      Get account.
      abstract ServiceManager.Block getBlock()
      Get last block information.
      static ServiceManager getInstance()
      Get singleton instance.
      abstract java.util.List<Event> getLastEventLogs()
      Get event logs of the last transaction.
      abstract <T> T getValue​(java.lang.Class<T> cls, Address address, java.lang.String key)
      Get value of the storage of the contract.
      abstract void invoke​(Account from, java.math.BigInteger value, Address targetAddress, java.lang.String method, java.lang.Object... params)
      Invoke specified method for write.
      abstract void setValue​(Address address, java.lang.String key, java.lang.Object value)
      Set value of the storage of the contract.
      abstract void transfer​(Account from, Address targetAddress, java.math.BigInteger value)
      Transfer native coin It simulates icx_sendTransaction with no dataType.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ServiceManager

        public ServiceManager()
    • Method Detail

      • deploy

        public abstract Score deploy​(Account caller,
                                     java.lang.Class<?> mainClass,
                                     java.lang.Object... params)
                              throws java.lang.Exception
        Deploy contract

        It simulates icx_sendTransaction with "deploy" dataType.

        Parameters:
        caller - Transaction sender
        mainClass - Smart contract main class to be deployed
        params - Parameters used for constructor.
        Returns:
        Score to manipulate others.
        Throws:
        java.lang.Exception - when it fails to deploy it.
      • createAccount

        public abstract Account createAccount()
        Create new EoA account.
        Returns:
        created account
      • createAccount

        public abstract Account createAccount​(int initialIcx)
        Create new EoA account with specified balance.
        Parameters:
        initialIcx - Initial balance of the account
        Returns:
        created account
      • getAccount

        public abstract Account getAccount​(Address addr)
        Get account.
        Parameters:
        addr - Address of the account
        Returns:
        If it's already created, then it returns otherwise, it would be created.
      • createScoreAccount

        public abstract Account createScoreAccount()
        Create new dummy smart contract account.
        Returns:
        created smart contract account.
      • deploy

        public abstract Score deploy​(Address addr,
                                     Account owner,
                                     java.lang.Object instance)
        Deploy SCORE on specified address.

        It may overwrite already deployed one. But the data will be kept. It can be used for simulating system contract.

        Parameters:
        addr - Address of the SCORE
        owner - Owner of the SCORE
        instance - Instance of smart contract
        Returns:
        Created SCORE
      • invoke

        public abstract void invoke​(Account from,
                                    java.math.BigInteger value,
                                    Address targetAddress,
                                    java.lang.String method,
                                    java.lang.Object... params)
        Invoke specified method for write. It simulates icx_sendTransaction with dataType "call".
        Parameters:
        from - Sender
        value - Value to transfer on call
        targetAddress - Receiver of the call
        method - Name of the method
        params - Parameters for the method
      • call

        public abstract java.lang.Object call​(Account from,
                                              java.math.BigInteger value,
                                              Address targetAddress,
                                              java.lang.String method,
                                              java.lang.Object... params)
        Call specified method. It simulates inter-call(or external-call). Use invoke(Account, BigInteger, Address, String, Object...) for external call.
        Parameters:
        from - Contract account for inter-call (EoA account for external-call)
        value - Value to transfer on the call
        targetAddress - Receiver of the call
        method - Name of the method
        params - Parameters for the method
        Returns:
        Returned value
      • call

        public abstract java.lang.Object call​(Address targetAddress,
                                              java.lang.String method,
                                              java.lang.Object... params)
        Call specified method for read. It simulates icx_call.
        Parameters:
        targetAddress - Receiver of the call
        method - Name of the method
        params - Parameters for the method
        Returns:
        Return value of the method as it is
      • call

        public abstract <T> T call​(java.lang.Class<T> cls,
                                   Address targetAddress,
                                   java.lang.String method,
                                   java.lang.Object... params)
        Call specified method for read. It simulates icx_call.
        Type Parameters:
        T - Return type It will throw exception on prohibited types.
        Parameters:
        cls - Return object type
        targetAddress - Receiver of the call
        method - Name of the method
        params - Parameters for the method
        Returns:
        Return value of the method converted to the specified type.
      • transfer

        public abstract void transfer​(Account from,
                                      Address targetAddress,
                                      java.math.BigInteger value)
        Transfer native coin It simulates icx_sendTransaction with no dataType.
        Parameters:
        from - Sender
        targetAddress - Receiver of the call
        value - Amount to transfer
      • getValue

        public abstract <T> T getValue​(java.lang.Class<T> cls,
                                       Address address,
                                       java.lang.String key)
        Get value of the storage of the contract.
        Type Parameters:
        T - Output return type
        Parameters:
        cls - Output object class
        address - Contract address
        key - Key for the storage
        Returns:
        Deserialized value
      • setValue

        public abstract void setValue​(Address address,
                                      java.lang.String key,
                                      java.lang.Object value)
        Set value of the storage of the contract.
        Parameters:
        address - Contract address
        key - Key for the storage
        value - Value to be stored
      • getBlock

        public abstract ServiceManager.Block getBlock()
        Get last block information.
        Returns:
        last block information
      • getLastEventLogs

        public abstract java.util.List<Event> getLastEventLogs()
        Get event logs of the last transaction.
        Returns:
        list of events
        See Also:
        GenerateTScore
      • getInstance

        public static ServiceManager getInstance()
        Get singleton instance.
        Returns:
        singleton instance of it