/// <summary> /// Applies an externally generated contract creation message to the current state. /// </summary> public StateTransitionResult Apply(IState state, ExternalCreateMessage message) { // We need to generate an address here so that we can set the initial balance. uint160 address = state.GenerateAddress(this.AddressGenerator); // For external creates we need to increment the balance state to take into // account any funds sent as part of the original contract invocation transaction. state.AddInitialTransfer(new TransferInfo { Value = message.Amount, To = address, From = message.From }); return(this.ApplyCreate(state, message.Parameters, message.Code, message, address)); }
/// <summary> /// Applies an externally generated contract creation message to the current state. /// </summary> public StateTransitionResult Apply(IState state, ExternalCreateMessage message) { var gasMeter = new GasMeter(message.GasLimit); gasMeter.Spend((Gas)GasPriceList.CreateCost); // We need to generate an address here so that we can set the initial balance. uint160 address = state.GenerateAddress(this.AddressGenerator); // For external creates we need to increment the balance state to take into // account any funds sent as part of the original contract invocation transaction. state.AddInitialTransfer(new TransferInfo(message.From, address, message.Amount)); return(ApplyCreate(state, message.Parameters, message.Code, message, address, gasMeter)); }
/// <summary> /// Applies an externally generated contract method call message to the current state. /// </summary> public StateTransitionResult Apply(IState state, ExternalCallMessage message) { byte[] contractCode = state.ContractState.GetCode(message.To); if (contractCode == null || contractCode.Length == 0) { return(StateTransitionResult.Fail((Gas)0, StateTransitionErrorKind.NoCode)); } // For external calls we need to increment the balance state to take into // account any funds sent as part of the original contract invocation transaction. state.AddInitialTransfer(new TransferInfo { Value = message.Amount, To = message.To, From = message.From }); return(this.ApplyCall(state, message, contractCode)); }
/// <summary> /// Applies an externally generated contract method call message to the current state. /// </summary> public StateTransitionResult Apply(IState state, ExternalCallMessage message) { var gasMeter = new GasMeter(message.GasLimit); gasMeter.Spend((Gas)GasPriceList.BaseCost); byte[] contractCode = state.ContractState.GetCode(message.To); if (contractCode == null || contractCode.Length == 0) { return(StateTransitionResult.Fail(gasMeter.GasConsumed, StateTransitionErrorKind.NoCode)); } // For external calls we need to increment the balance state to take into // account any funds sent as part of the original contract invocation transaction. state.AddInitialTransfer(new TransferInfo(message.From, message.To, message.Amount)); return(ApplyCall(state, message, contractCode, gasMeter)); }