authenteq-zz / java-bigchaindb-driver

Official BigchainDB Java driver
https://www.bigchaindb.com
Apache License 2.0
32 stars 22 forks source link

Confusion regarding asset id. #75

Open devender-yadav opened 6 years ago

devender-yadav commented 6 years ago

Can user set asset id while adding asset for CREATE transaction?

I can see Asset.java with a setter for Id.

But addAssets( Object assets, Class assetsDataClass ) of BigchainDbTransactionBuilder.Builder() takes asset data & class and there is no way of supplying Asset id.


Even if it's not, I want to get bigchaindb generated asset id.

I sent a transaction. Sample code:

KeyPairGenerator generator = new KeyPairGenerator();
KeyPair keyPair = generator.generateKeyPair();

Map<String, String> data = new HashMap<>();
data.put("city", "Delhi");
data.put("country", "India");
data.put("date", "28/03/2018");

Map<String, String> metaData = new HashMap<>();
metaData.put("planet", "Earth");

Transaction transaction = BigchainDbTransactionBuilder.init().addAssets(data, data.getClass())
    .addMetaData(metaData).operation(Operations.CREATE)
    .buildAndSign(((EdDSAPublicKey) publicKey), ((EdDSAPrivateKey) privateKey)).sendTransaction();

And I waited till StatusCode.VALID

But transaction.getAsset().getId() is null.

And https://test.bigchaindb.com/api/v1/assets?search=India returning both data and id

Sample response:

[
  {
    "data": {
      "city": "Delhi",
      "country": "India",
      "date": "28/03/2018"
    },
    "id": "00c2cdf6b6213197d3ba3e7198ca9ef913ee42bb1f0b1399f00a84b5f57f31f1"
  }
]
devender-yadav commented 6 years ago

idreturned by https://test.bigchaindb.com/api/v1/assets?search=<text> is transaction id.

adonnini commented 6 years ago

Hi,

I am not sure this is relevant.

From the documentation:

https://docs.bigchaindb.com/projects/js-driver/en/latest/usage.html#asset-creation

"In the assets search the call returns the asset id which is the same id of the transaction that created the asset."

Thanks,

Alex Donnini

adonnini commented 6 years ago

Hi,

I also looked through the code and could not find an instance where asset id was set/generated in the process of building a transaction.

The test app seems to be old. It does include code to set asset id.

One could certainly include asset id a field in the asset data included in a transaction.

Thanks,

Alex

adonnini commented 6 years ago

Hi,

Sorry for this third comment.

I tried:

    Transaction transaction2 = new Transaction();

    Asset asset = new Asset();

    asset.setId("MobilityAsset001");

    Log.i(TAG, " - SendTransaction - doInBackground - asset.getId() - " + asset.getId());

    transaction2.setAsset(asset);

The log statement reported the asset id as being "MobilityAsset001"

However, when I tried to retrieve the asset id after processing transaction2, the asset id returned was still null

Thanks,

Alex Donnini

devender-yadav commented 6 years ago

Hi @adonnini,

Thanks for the documentation link. Null asset id seems like a bug to me.

-Dev