wharfkit / antelope

Core types, client interfaces, and other tools for working with Antelope-based blockchains.
Other
44 stars 23 forks source link

Adding transaction data to the TransactionReceipt #9

Closed aaroncox closed 2 years ago

aaroncox commented 3 years ago

I'd like to add in the trx field to the TransactionReceipt class, but with it returning different data types conditionally based on the status, I'm not entirely sure how to do that.

The code in question is:

https://github.com/greymass/eosio-core/blob/9f1d6676bc4957b60205ca0d65eac40697aafe74/src/chain/transaction.ts#L203-L208

You can see an example of the different types of data in the trx field in our tests here:

https://github.com/greymass/eosio-core/blob/9f1d6676bc4957b60205ca0d65eac40697aafe74/test/data/f3ada964795e1371af75486638632e6b04f37035.json#L11-L27

It looks to be either a Checksum256 if the transaction is expired, or a PackedTransaction if the transaction is executed.

jnordberg commented 3 years ago

There is no builtin ABI type that can represent fc::static_variant, so you would need to implement that using the ABISerializableObject interface. Problem with that is that the json data fc encodes it to does not contain any information about which type it actually encoded. So there would be no way to differentiate between e.g. a name and a uint64 because they are both represented as strings in fc's json representation.

Another option is to implement some sort of Checksum256OrPackedTransaction type that figures out which one of the types it is in the from factory, it seems it would be possible in this case. But IMO we should just treat these kind of API response types as any and add a typescript interface type hint to it where possible.

E.g.


type MaybeThings = string | {foo: string}

 @Struct.type('api_respone') 
 export class APIResponse extends Struct { 
     @Struct.field('string') status!: string 
     @Struct.field('any') something!: MaybeThings
 }