contract EscrowMaintainContract is PartnerAuthority {
  address public pledgeFactory;

  // map of token name to token pool address;
  mapping(string => address) internal nameByPool;
  // map of token name to erc20 token address;
  mapping(string => address) internal nameByToken;



  // -----------------------------------------
  // External interface
  // -----------------------------------------

  /**
   * @dev Create a pledge subcontract
   * @param _pledgeId index number of the pledge contract.
   */
  function createPledgeContract(uint256 _pledgeId) public onlyPartner returns(bool) {
    require(_pledgeId > 0 && pledgeFactory!=address(0));
    require(PledgeFactory(pledgeFactory).createPledgeContract(_pledgeId,partner));
    return true;
  }


  /**
   * @dev Batch create a pledge subcontract
   * @param _pledgeIds index number of the pledge contract.
   */
  function batchCreatePledgeContract(uint256[] _pledgeIds) public onlyPartner {
    require(_pledgeIds.length > 0);
    PledgeFactory(pledgeFactory).batchCreatePledgeContract(_pledgeIds,partner);
  }


  /**
   * @dev Use the index to get the basic information of the corresponding pledge contract.
   * @param _pledgeId index number of the pledge contract
   */
  function getEscrowPledge(uint256 _pledgeId) public view returns(string tokenName, address pledgeContract) {
    require(_pledgeId > 0);
    (tokenName,pledgeContract) = PledgeFactory(pledgeFactory).getEscrowPledge(_pledgeId);
  }


  /**
   * @dev setTokenPool, set the token pool contract address of a token name.
   * @param _tokenName set token pool name.
   * @param _address the token pool contract address.
   */
  function setTokenPool(string _tokenName, address _address) public onlyOwner {
    require(_address != address(0) && bytes(_tokenName).length > 0);
    nameByPool[_tokenName] = _address;
  }

   /**
   * @dev setToken, set the token contract address of a token name.
   * @param _tokenName token name
   * @param _address the ERC20 token contract address.
   */
  function setToken(string _tokenName, address _address) public onlyOwner {
    require(_address != address(0) && bytes(_tokenName).length > 0);
    nameByToken[_tokenName] = _address;
  }


  /**
  * @dev setPledgeFactory, Plant contract for configuration management pledge business.
  * @param _factory pledge factory contract.
  */
  function setPledgeFactory(address _factory) public onlyOwner {
    require(_factory != address(0));
    pledgeFactory = _factory;
  }

  /**
   * @dev Checks whether the current token pool is supported.
   * @param _tokenName token name
   */
  function includeTokenPool(string _tokenName) view public returns(address) {
    require(bytes(_tokenName).length > 0);
    return nameByPool[_tokenName];
  }


  /**
   * @dev Checks whether the current erc20 token is supported.
   * @param _tokenName token name
   */
  function includeToken(string _tokenName) view public returns(address) {
    require(bytes(_tokenName).length > 0);
    return nameByToken[_tokenName];
  }

}
/**
 * @title EscrowMaintainContract
 * @dev Provides configuration and external interfaces.
 */
function createPledgeContract(uint256 _pledgeId) public onlyPartner returns(bool) {
  require(_pledgeId > 0 && pledgeFactory!=address(0));
  require(PledgeFactory(pledgeFactory).createPledgeContract(_pledgeId,partner));
  return true;
}

/**
 * @dev Create a pledge subcontract
 * @param _pledgeId index number of the pledge contract.
 */