enjin / platform-csharp-sdk

SDK for connecting to and interacting with the Enjin Platform.
GNU Lesser General Public License v3.0
7 stars 8 forks source link

Added SetupFromRequestObject helper #19

Closed CliffCawley closed 6 months ago

CliffCawley commented 6 months ago

This helps when interacting with a fuel tank.

I.e. if you are using a MintToken request:

var reqMint = new MintToken()
    .SetRecipient(walletAddress)

You can now just pass this in and have it auto translated for use:

var reqDispatch = new DispatchAndTouch()
    .SetTankId("ABC")
    .SetRuleSetId(1)
    .SetDispatch(new DispatchInputType()
        // Pass the request object in and have it auto setup
        .SetupFromRequestObject(reqMint, DispatchCall.MultiTokens)
    );

Additionally, the SetupFromRequestObject call also checks if it's a TransactionFragment and calls WithId and WithEncodedData, both of which are required by the Dispatch call

CliffCawley commented 6 months ago

Actually, I refactored this from some other code I was using, and only just realised it's going to fail at runtime, because the JsonDocument goes out of context.

I'll need to come up with another way to do this, since "variables" requires a JsonElement.

The class could keep a JsonDocument around, but then would require a dispose pattern and require consumers to wrap it in a using :(