Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting Additional GAS to be used in RpcInvoke for RpcServer. Expose overloaded ApplicationEngine.Run allowing a passed Snapshot. #397

Merged
merged 11 commits into from
Oct 17, 2018
5 changes: 3 additions & 2 deletions neo/NeoSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ public void StartNode(int port = 0, int ws_port = 0)
});
}

public void StartRpc(IPAddress bindAddress, int port, Wallet wallet = null, string sslCert = null, string password = null, string[] trustedAuthorities = null)
public void StartRpc(IPAddress bindAddress, int port, Wallet wallet = null, string sslCert = null, string password = null,
string[] trustedAuthorities = null, long maxGasInvoke = 99000000000L)
{
rpcServer = new RpcServer(this, wallet);
rpcServer = new RpcServer(this, wallet, maxGasInvoke);
rpcServer.Start(bindAddress, port, sslCert, password, trustedAuthorities);
}
}
Expand Down
8 changes: 5 additions & 3 deletions neo/Network/RPC/RpcServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ public sealed class RpcServer : IDisposable
private readonly NeoSystem system;
private readonly Wallet wallet;
private IWebHost host;
private Fixed8 maxGasInvoke;

public RpcServer(NeoSystem system, Wallet wallet = null)
public RpcServer(NeoSystem system, Wallet wallet = null, long maxGasInvoke = 99000000000L)
{
this.system = system;
this.wallet = wallet;
this.maxGasInvoke = new Fixed8(maxGasInvoke);
}

private static JObject CreateErrorResponse(JObject id, int code, string message, JObject data = null)
Expand Down Expand Up @@ -71,7 +73,7 @@ public void Dispose()

private JObject GetInvokeResult(byte[] script)
{
ApplicationEngine engine = ApplicationEngine.Run(script);
ApplicationEngine engine = ApplicationEngine.Run(script, null, null, false, maxGasInvoke);
JObject json = new JObject();
json["script"] = script.ToHexString();
json["state"] = engine.State;
Expand Down Expand Up @@ -695,4 +697,4 @@ public void Start(IPAddress bindAddress, int port, string sslCert = null, string
host.Start();
}
}
}
}
48 changes: 27 additions & 21 deletions neo/SmartContract/ApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -610,30 +610,36 @@ private bool PreStepInto(OpCode nextOpcode)
return true;
}

public static ApplicationEngine Run(byte[] script, IScriptContainer container = null, Block persisting_block = null, bool testMode = false)
public static ApplicationEngine Run(byte[] script, Snapshot snapshot,
IScriptContainer container = null, Block persistingBlock = null, bool testMode = false, Fixed8 extraGAS = default(Fixed8))
{
using (Snapshot snapshot = Blockchain.Singleton.GetSnapshot())
snapshot.PersistingBlock = persistingBlock ?? snapshot.PersistingBlock ?? new Block
{
snapshot.PersistingBlock = persisting_block ?? new Block
Version = 0,
PrevHash = snapshot.CurrentBlockHash,
MerkleRoot = new UInt256(),
Timestamp = snapshot.Blocks[snapshot.CurrentBlockHash].TrimmedBlock.Timestamp + Blockchain.SecondsPerBlock,
Index = snapshot.Height + 1,
ConsensusData = 0,
NextConsensus = snapshot.Blocks[snapshot.CurrentBlockHash].TrimmedBlock.NextConsensus,
Witness = new Witness
{
Version = 0,
PrevHash = snapshot.CurrentBlockHash,
MerkleRoot = new UInt256(),
Timestamp = snapshot.Blocks[snapshot.CurrentBlockHash].TrimmedBlock.Timestamp + Blockchain.SecondsPerBlock,
Index = snapshot.Height + 1,
ConsensusData = 0,
NextConsensus = snapshot.Blocks[snapshot.CurrentBlockHash].TrimmedBlock.NextConsensus,
Witness = new Witness
{
InvocationScript = new byte[0],
VerificationScript = new byte[0]
},
Transactions = new Transaction[0]
};
ApplicationEngine engine = new ApplicationEngine(TriggerType.Application, container, snapshot, Fixed8.Zero, testMode);
engine.LoadScript(script);
engine.Execute();
return engine;
InvocationScript = new byte[0],
VerificationScript = new byte[0]
},
Transactions = new Transaction[0]
};
ApplicationEngine engine = new ApplicationEngine(TriggerType.Application, container, snapshot, extraGAS, testMode);
engine.LoadScript(script);
engine.Execute();
return engine;
}

public static ApplicationEngine Run(byte[] script, IScriptContainer container = null, Block persistingBlock = null, bool testMode = false, Fixed8 extraGAS = default(Fixed8))
{
using (Snapshot snapshot = Blockchain.Singleton.GetSnapshot())
{
return Run(script, snapshot, container, persistingBlock, testMode, extraGAS);
}
}
}
Expand Down