Skip to content

Commit

Permalink
allow CheckWitness to always return true
Browse files Browse the repository at this point in the history
  • Loading branch information
Hecate2 committed Oct 31, 2024
1 parent 6cd0ed3 commit 17e7c3e
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Fairy.Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public RuntimeArgs(Wallet fairyWallet)
public Wallet fairyWallet;
public ulong? timestamp = null;
public BigInteger? designatedRandom = null;
public bool checkWitnessReturnTrue = false;

public object Clone() => MemberwiseClone();
//public uint? blockIndex = null;
Expand Down Expand Up @@ -153,6 +154,8 @@ public InteropDescriptor Register(string name, MethodInfo method, uint hash, lon
return descriptor;
}

public new bool CheckWitness(byte[] hashOrPubkey) => base.CheckWitness(hashOrPubkey);
public bool CheckFairyWitness(byte[] hashOrPubkey) => runtimeArgs.checkWitnessReturnTrue || CheckWitness(hashOrPubkey);
public new BigInteger GetRandom() => base.GetRandom();
public BigInteger GetFairyRandom() => runtimeArgs.designatedRandom != null ? (BigInteger)runtimeArgs.designatedRandom : base.GetRandom();
public new ulong GetTime()
Expand Down Expand Up @@ -230,6 +233,33 @@ protected virtual JToken GetSnapshotRandom(JArray _params)
return json;
}

[RpcMethod]
protected virtual JToken SetSnapshotCheckWitness(JArray _params)
{
string session = _params[0]!.AsString();
bool setValue = _params[1]!.AsBoolean();
FairySession fairySession = sessionStringToFairySession[session];
fairySession.checkWitnessReturnTrue = setValue;
JObject json = new();
json[session] = setValue;
return json;
}

[RpcMethod]
protected virtual JToken GetSnapshotCheckWitness(JArray _params)
{
JObject json = new();
foreach (var s in _params)
{
string session = s!.AsString();
if (sessionStringToFairySession.ContainsKey(session))
json[session] = sessionStringToFairySession[session].checkWitnessReturnTrue;
else
json[session] = null;
}
return json;
}

private static Block CreateDummyBlockWithTimestamp(DataCache snapshot, ProtocolSettings settings, ulong? timestamp = null, uint? index = null)
{
UInt256 hash = NativeContract.Ledger.CurrentHash(snapshot);
Expand Down Expand Up @@ -302,6 +332,24 @@ public BigInteger? designatedRandom
}
}

public bool checkWitnessReturnTrue
{
get => engine.runtimeArgs.checkWitnessReturnTrue;
set
{
if (value == false)
{
engine.Register("System.Runtime.CheckWitness", typeof(FairyEngine).GetMethod(nameof(FairyEngine.CheckWitness))!, ApplicationEngine.System_Runtime_CheckWitness.Hash, 1 << 10, CallFlags.None);
engine.runtimeArgs.checkWitnessReturnTrue = value;
}
else
{
engine.runtimeArgs.checkWitnessReturnTrue = value;
engine.Register("System.Runtime.CheckWitness", typeof(FairyEngine).GetMethod(nameof(FairyEngine.CheckFairyWitness))!, ApplicationEngine.System_Runtime_CheckWitness.Hash, 1 << 10, CallFlags.None);
}
}
}

public void ResetServices()
{
engine.runtimeArgs = new(fairy.defaultFairyWallet);
Expand Down

0 comments on commit 17e7c3e

Please sign in to comment.