private void setUpMockitoRules() throws Exception {

    when(mockDatabase.getDatabaseFactory()).thenReturn(mockDatabaseFactory);
    when(mockDatabaseTable.getEmptyRecord()).thenReturn(mockDatabaseTableRecord);
    when(mockDatabase.getTable(AssetIssuingDatabaseConstants.ASSET_ISSUING_TABLE_NAME))
        .thenReturn(mockDatabaseTable);
    when(pluginDatabaseSystem.openDatabase(
            pluginId, AssetIssuingDatabaseConstants.ASSET_ISSUING_DATABASE))
        .thenReturn(mockDatabase);

    //        when(mockExtraUserActorDatabaseFactory.createDatabase(pluginId,
    // pluginId.toString())).thenReturn(mockDatabase);
    when(deviceUser.getPublicKey()).thenReturn("myPublicKey");
    when(deviceUserManager.getLoggedInDeviceUser()).thenReturn(deviceUser);
    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener1);
    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener2);
    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_REVERSED_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener3);
    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_REVERSED_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener4);
    when(eventManager.getNewListener(EventType.RECEIVED_NEW_DIGITAL_ASSET_METADATA_NOTIFICATION))
        .thenReturn(fermatEventListener5);

    when(actorAssetIssuerManager.getActorAssetIssuer()).thenReturn(actorAssetIssuer);
  }
Пример #2
0
  /**
   * first i persist private key on a file second i insert the record in database third i save the
   * profile image file
   *
   * @param alias
   * @param publicKey
   * @param privateKey
   * @param deviceUser
   * @param profileImage
   * @throws CantCreateArtistIdentityException
   */
  public void createNewUser(
      String alias, String publicKey, String privateKey, DeviceUser deviceUser, byte[] profileImage)
      throws CantCreateArtistIdentityException {

    try {
      if (aliasExists(alias)) {
        throw new CantCreateArtistIdentityException(
            "Cant create new Redeem Point Identity, alias exists.",
            "Redeem Point Identity",
            "Cant create new Redeem Point, alias exists.");
      }

      persistNewUserPrivateKeysFile(publicKey, privateKey);

      DatabaseTable table =
          this.database.getTable(ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_TABLE_NAME);
      DatabaseTableRecord record = table.getEmptyRecord();

      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_PUBLIC_KEY_COLUMN_NAME, publicKey);
      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_ALIAS_COLUMN_NAME, alias);
      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_DEVICE_USER_PUBLIC_KEY_COLUMN_NAME,
          deviceUser.getPublicKey());

      table.insertRecord(record);

      if (profileImage != null) persistNewUserProfileImage(publicKey, profileImage);

    } catch (CantInsertRecordException e) {
      // Cant insert record.
      throw new CantCreateArtistIdentityException(
          e.getMessage(),
          e,
          "Redeem Point Identity",
          "Cant create new Redeem Point, insert database problems.");

    } catch (CantPersistPrivateKeyException e) {
      // Cant insert record.
      throw new CantCreateArtistIdentityException(
          e.getMessage(),
          e,
          "ARedeem Point Identity",
          "Cant create new Redeem Point, persist private key error.");

    } catch (Exception e) {
      // Failure unknown.

      throw new CantCreateArtistIdentityException(
          e.getMessage(),
          FermatException.wrapException(e),
          "Redeem Point Identity",
          "Cant create new Redeem Point, unknown failure.");
    }
  }
  private void setUpMockitoRules() throws Exception {

    when(mockDatabase.getDatabaseFactory()).thenReturn(mockDatabaseFactory);
    when(mockDatabaseTable.getEmptyRecord()).thenReturn(mockDatabaseTableRecord);
    when(mockDatabase.getTable(
            AssetIssuingTransactionDatabaseConstants.DIGITAL_ASSET_TRANSACTION_TABLE_NAME))
        .thenReturn(mockDatabaseTable);
    when(mockDatabase.getTable(
            AssetIssuingTransactionDatabaseConstants
                .DIGITAL_ASSET_TRANSACTION_ASSET_ISSUING_TABLE_NAME))
        .thenReturn(mockDatabaseTable2);
    when(mockDatabaseTable2.getEmptyRecord()).thenReturn(mockDatabaseTableRecord);
    when(mockDatabaseTable2.getRecords()).thenReturn(records);
    when(pluginDatabaseSystem.openDatabase(
            pluginId, AssetIssuingTransactionDatabaseConstants.DIGITAL_ASSET_TRANSACTION_DATABASE))
        .thenReturn(mockDatabase);

    when(deviceUser.getPublicKey()).thenReturn("myPublicKey");
    when(deviceUserManager.getLoggedInDeviceUser()).thenReturn(deviceUser);

    when(actorAssetIssuerManager.getActorAssetIssuer()).thenReturn(actorAssetIssuer);

    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener1);
    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener2);
    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_REVERSED_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener3);
    when(eventManager.getNewListener(
            EventType.INCOMING_ASSET_REVERSED_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_ISSUER))
        .thenReturn(fermatEventListener4);

    when(pluginFileSystem.createTextFile(
            this.pluginId,
            "digital-asset-issuing/publicKey",
            "name.xml",
            FilePrivacy.PUBLIC,
            FileLifeSpan.PERMANENT))
        .thenReturn(pluginTextFile);
    when(bitcoinWalletManager.loadWallet(this.walletPublicKey)).thenReturn(bitcoinWalletWallet);
    when(bitcoinWalletWallet.getBalance(BalanceType.AVAILABLE)).thenReturn(bitcoinWalletBalance);
    when(bitcoinWalletBalance.getBalance()).thenReturn(bitcoinWalletAvailableBalance);
    when(assetVaultManager.getNewAssetVaultCryptoAddress(this.blockchainNetworkType))
        .thenReturn(cryptoAddress);
    //        doNothing().when(assetIssuingPluginRoot).issueAssets(digitalAsset, 1, walletPublicKey,
    // blockchainNetworkType);
  }
  public List<RedeemPointIdentity> getIdentityAssetRedeemPointsFromCurrentDeviceUser(
      DeviceUser deviceUser) throws CantListAssetRedeemPointIdentitiesException {

    // Setup method.
    List<RedeemPointIdentity> list = new ArrayList<>(); // Intra User list.
    DatabaseTable table; // Intra User table.

    // Get Redeem Point identities list.
    try {

      /** 1) Get the table. */
      table =
          this.database.getTable(
              AssetRedeemPointIdentityDatabaseConstants.ASSET_REDEEM_POINT_IDENTITY_TABLE_NAME);

      if (table == null) {
        /** Table not found. */
        throw new CantGetUserDeveloperIdentitiesException(
            "Cant get Asset Issuer identity list, table not found.",
            "Asset IssuerIdentity",
            "Cant get Intra User identity list, table not found.");
      }

      // 2) Find the Redeem Point.
      table.setStringFilter(
          AssetRedeemPointIdentityDatabaseConstants
              .ASSET_REDEEM_POINT_IDENTITY_DEVICE_USER_PUBLIC_KEY_COLUMN_NAME,
          deviceUser.getPublicKey(),
          DatabaseFilterType.EQUAL);
      table.loadToMemory();

      // 3) Get Redeem Point.
      for (DatabaseTableRecord record : table.getRecords()) {

        // Add records to list.
        list.add(
            new IdentityAssetRedeemPointImpl(
                record.getStringValue(
                    AssetRedeemPointIdentityDatabaseConstants
                        .ASSET_REDEEM_POINT_IDENTITY_ALIAS_COLUMN_NAME),
                record.getStringValue(
                    AssetRedeemPointIdentityDatabaseConstants
                        .ASSET_REDEEM_POINT_IDENTITY_PUBLIC_KEY_COLUMN_NAME),
                getAssetIssuerIdentityPrivateKey(
                    record.getStringValue(
                        AssetRedeemPointIdentityDatabaseConstants
                            .ASSET_REDEEM_POINT_IDENTITY_PUBLIC_KEY_COLUMN_NAME)),
                getAssetIssuerProfileImagePrivateKey(
                    record.getStringValue(
                        AssetRedeemPointIdentityDatabaseConstants
                            .ASSET_REDEEM_POINT_IDENTITY_DEVICE_USER_PUBLIC_KEY_COLUMN_NAME)),
                pluginFileSystem,
                pluginId));
      }
    } catch (CantLoadTableToMemoryException e) {
      throw new CantListAssetRedeemPointIdentitiesException(
          e.getMessage(),
          e,
          "Asset Redeem Point Identity",
          "Cant load "
              + AssetRedeemPointIdentityDatabaseConstants.ASSET_REDEEM_POINT_IDENTITY_TABLE_NAME
              + " table in memory.");
    } catch (CantGetAssetRedeemPointIdentityPrivateKeyException e) {
      // Failure unknown.
      throw new CantListAssetRedeemPointIdentitiesException(
          e.getMessage(), e, "Asset Redeem Point Identity", "Can't get private key.");

    } catch (Exception e) {
      throw new CantListAssetRedeemPointIdentitiesException(
          e.getMessage(),
          FermatException.wrapException(e),
          "Asset Redeem Point Identity",
          "Cant get Asset Issuer identity list, unknown failure.");
    }

    // Return the list values.
    return list;
  }
Пример #5
0
  public List<Artist> getIdentityArtistsFromCurrentDeviceUser(DeviceUser deviceUser)
      throws CantListArtistIdentitiesException {

    // Setup method.
    List<Artist> list = new ArrayList<>(); // Intra User list.
    DatabaseTable table; // Intra User table.

    // Get Redeem Point identities list.
    try {

      /** 1) Get the table. */
      table = this.database.getTable(ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_TABLE_NAME);

      if (table == null) {
        /** Table not found. */
        throw new CantUpdateArtistIdentityException(
            "Cant get Asset Issuer identity list, table not found.",
            "Asset IssuerIdentity",
            "Cant get Intra User identity list, table not found.");
      }

      // 2) Find the Redeem Point.
      table.addStringFilter(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_DEVICE_USER_PUBLIC_KEY_COLUMN_NAME,
          deviceUser.getPublicKey(),
          DatabaseFilterType.EQUAL);
      table.loadToMemory();

      // 3) Get Redeem Point.
      for (DatabaseTableRecord record : table.getRecords()) {

        // Add records to list.
        /*list.add(new IdentityAssetRedeemPointImpl(record.getStringValue(ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_ALIAS_COLUMN_NAME),
        record.getStringValue(ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_PUBLIC_KEY_COLUMN_NAME),
        getArtistIdentityPrivateKey(record.getStringValue(ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_PUBLIC_KEY_COLUMN_NAME)),
        getArtistProfileImagePrivateKey(record.getStringValue(ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_PUBLIC_KEY_COLUMN_NAME)),
        pluginFileSystem,
        pluginId), );*/
        list.add(
            new ArtistIdentityImp(
                record.getStringValue(
                    ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_ALIAS_COLUMN_NAME),
                record.getStringValue(
                    ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_PUBLIC_KEY_COLUMN_NAME),
                record.getStringValue(
                    ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_EXTERNAL_USER_NAME_COLUMN_NAME),
                record.getStringValue(
                    ArtistIdentityDatabaseConstants
                        .ARTIST_IDENTITY_EXTERNAL_ACCESS_TOKEN_COLUMN_NAME),
                ExternalPlatform.getByCode(
                    record.getStringValue(
                        ArtistIdentityDatabaseConstants
                            .ARTIST_IDENTITY_EXTERNAL_PLATFORM_COLUMN_NAME)),
                ExposureLevel.getByCode(
                    record.getStringValue(
                        ArtistIdentityDatabaseConstants
                            .ARTIST_IDENTITY_EXPOSURE_LEVEL_COLUMN_NAME)),
                ArtistAcceptConnectionsType.getByCode(
                    record.getStringValue(
                        ArtistIdentityDatabaseConstants
                            .ARTIST_IDENTITY_ACEEPTS_CONNECTIONS_TYPE_COLUMN_NAME)),
                pluginFileSystem,
                pluginId));
      }
    } catch (CantLoadTableToMemoryException e) {
      throw new CantListArtistIdentitiesException(
          e.getMessage(),
          e,
          "Asset Redeem Point Identity",
          "Cant load "
              + ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_TABLE_NAME
              + " table in memory.");
    } catch (Exception e) {
      throw new CantListArtistIdentitiesException(
          e.getMessage(),
          FermatException.wrapException(e),
          "Asset Redeem Point Identity",
          "Cant get Asset Issuer identity list, unknown failure.");
    }

    // Return the list values.
    return list;
  }
Пример #6
0
  /**
   * first i persist private key on a file second i insert the record in database third i save the
   * profile image file
   *
   * @param alias
   * @param publicKey
   * @param privateKey
   * @param deviceUser
   * @param profileImage
   * @throws CantCreateArtistIdentityException
   */
  public void createNewUser(
      String alias,
      String publicKey,
      String privateKey,
      DeviceUser deviceUser,
      byte[] profileImage,
      String externalUserName,
      String externalAccessToken,
      ExternalPlatform externalPlatform,
      ExposureLevel exposureLevel,
      ArtistAcceptConnectionsType artistAcceptConnectionsType)
      throws CantCreateArtistIdentityException {

    try {
      if (aliasExists(alias)) {
        throw new CantCreateArtistIdentityException(
            "Cant create new Redeem Point Identity, alias exists.",
            "Redeem Point Identity",
            "Cant create new Redeem Point, alias exists.");
      }

      persistNewUserPrivateKeysFile(publicKey, privateKey);

      DatabaseTable table =
          this.database.getTable(ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_TABLE_NAME);
      DatabaseTableRecord record = table.getEmptyRecord();

      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_PUBLIC_KEY_COLUMN_NAME, publicKey);
      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_DEVICE_USER_PUBLIC_KEY_COLUMN_NAME,
          deviceUser.getPublicKey());
      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_ALIAS_COLUMN_NAME, alias);
      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_EXTERNAL_USER_NAME_COLUMN_NAME,
          externalUserName);
      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_EXTERNAL_ACCESS_TOKEN_COLUMN_NAME,
          externalAccessToken);
      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_EXTERNAL_PLATFORM_COLUMN_NAME,
          externalPlatform.getCode());
      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_EXPOSURE_LEVEL_COLUMN_NAME,
          exposureLevel.getCode());
      record.setStringValue(
          ArtistIdentityDatabaseConstants.ARTIST_IDENTITY_ACEEPTS_CONNECTIONS_TYPE_COLUMN_NAME,
          artistAcceptConnectionsType.getCode());

      table.insertRecord(record);

      if (profileImage != null) persistNewUserProfileImage(publicKey, profileImage);

    } catch (CantInsertRecordException e) {
      // Cant insert record.
      throw new CantCreateArtistIdentityException(
          e.getMessage(),
          e,
          "Redeem Point Identity",
          "Cant create new Redeem Point, insert database problems.");

    } catch (CantPersistPrivateKeyException e) {
      // Cant insert record.
      throw new CantCreateArtistIdentityException(
          e.getMessage(),
          e,
          "ARedeem Point Identity",
          "Cant create new Redeem Point, persist private key error.");

    } catch (Exception e) {
      // Failure unknown.

      throw new CantCreateArtistIdentityException(
          e.getMessage(),
          FermatException.wrapException(e),
          "Redeem Point Identity",
          "Cant create new Redeem Point, unknown failure.");
    }
  }