public void SaveContract(BaseContract contract) { if (contract.Address == this.integration.contractRegistryAddress) { throw new ArgumentOutOfRangeException(contract.Address + " is a magic address which cannot be used for contracts."); } if (contract is NonexistentContract) { return; } var data = StrongForceSerialization.SerializeStatefulObject(contract); var typeName = Encoding.ASCII.GetBytes(contract.GetType().Name); this.SaveData(contract.Address, data, typeName); this.integration.logger.LogTrace("Saved contract data: " + data.Length + " bytes for " + contract.Address); }
public void Serializes_And_Deserializes_Contracts() { var address = new Address(new byte[] { 10, 20, 127, 54, 51 }); var adminAddress = new Address(new byte[] { 10, 20, 4 }); var contract = StatefulObject.Create <FavoriteNumberContract>(new Dictionary <string, object> { { "Admin", adminAddress.ToString() }, { "Number", 15 } }); contract.RegisterWithRegistry(new InMemoryIntegration.FakeContractContext(address)); var serializedContract = StrongForceSerialization.SerializeStatefulObject(contract); var deserializedContract = (FavoriteNumberContract)StrongForceSerialization.DeserializeStatefulObject(serializedContract); deserializedContract.RegisterWithRegistry(new InMemoryIntegration.FakeContractContext(address)); Assert.Equal(contract.GetState(), deserializedContract.GetState()); Assert.Equal(contract.Address, deserializedContract.Address); Assert.Equal(contract.Number, deserializedContract.Number); }
public Task StartAsync(CancellationToken cancellationToken) { var initialKit = (KitContract)StatefulObject.Create( this.settings.InitialKitType, this.settings.InitialKitPayload); initialKit.RegisterWithRegistry( new InMemoryIntegration.FakeContractContext( KitContract.DefaultAddress)); var facade = new CosmosIntegration( this.logger, StrongForceSerialization.SerializeStatefulObject(initialKit)); this.server = new Server { Services = { Strongforce.StrongForce.BindService(facade) }, Ports = { new ServerPort(this.settings.Hostname, this.settings.Port, ServerCredentials.Insecure) }, }; this.server.Start(); return(Task.CompletedTask); }