Interface ContractStateVaultJsonFactory

  • All Implemented Interfaces:

    
    public interface ContractStateVaultJsonFactory<T extends ContractState>
    
                        

    Implement a ContractStateVaultJsonFactory to create a JSON representation of a state to store alongside the state in the vault. This JSON representation can be used to query states from flows using query.

    Classes that implement ContractStateVaultJsonFactory will be executed in a hierarchical way. That means every factory that belongs to a given state or that given state's ancestors will be executed and the end result will be a combined JSON. The combined JSON will be keyed by the state type specified by the factory.

    In order to perform a "query by state" query using `UtxoLedgerService.query` for a particular state type, a factory for that given type must be present, even if it's just returning an empty JSON string.

    Please note that only one factory can be registered for a state type.

    Example usage:

    • Kotlin:
      
      class TestUtxoStateVaultJsonFactory: ContractStateVaultJsonFactory<TestUtxoState> {
      
          private data class TestUtxoStatePojo(val testField: String)
      
          override val stateType: Class<TestUtxoState> = TestUtxoState::class.java
      
          override fun append(state: TestUtxoState, jsonMarshallingService: JsonMarshallingService): String {
              return jsonMarshallingService.format(TestUtxoStatePojo(state.testField))
          }
      }
      
      
    • Java:
      
      public class TestUtxoStateVaultJsonFactory implements ContractStateVaultJsonFactory<TestUtxoState> {
      
          private class TestUtxoStatePojo {
              private String testField;
      
              TestUtxoStatePojo(String testField) {
                  this.testField = testField;
              }
      
              String getTestField() {
                  return this.testField;
              }
          }
      
          
          public Class<T> getStateType() {
              return TestUtxoState.class;
          }
      
          
          public String append(TestUtxoState state, JsonMarshallingService jsonMarshallingService) {
              return jsonMarshallingService.format(new TestUtxoStatePojo(state.getTestField()));
          }
      }
      
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      abstract Class<T> getStateType()
      abstract String create(@NotNull() T state, @NotNull() JsonMarshallingService jsonMarshallingService) The function that defines how the given state can be represented as a JSON string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • create

        @NotNull() abstract String create(@NotNull() T state, @NotNull() JsonMarshallingService jsonMarshallingService)

        The function that defines how the given state can be represented as a JSON string.

        Parameters:
        state - The state object.
        jsonMarshallingService - An instance of a JsonMarshallingService that can be used when creating a JSON representation.