Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
merl111 committed Nov 5, 2021
2 parents 3962b2c + bb25aba commit 34e8c7d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 10 deletions.
16 changes: 13 additions & 3 deletions Spook/Command/CommandDispatcher.Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,19 @@ protected void OnCreatePlatformToken(string[] args)
return;
}

tx = GenerateToken(_cli.NodeKeys, symbol, name, maxSupply, decimals,
TokenFlags.Fungible | TokenFlags.Transferable | TokenFlags.Divisible
| TokenFlags.Burnable);
var flags = TokenFlags.Fungible | TokenFlags.Transferable | TokenFlags.Burnable;

if (decimals > 0)
{
flags = flags | TokenFlags.Divisible;
}

if (maxSupply > 0)
{
flags = flags | TokenFlags.Finite;
}

tx = GenerateToken(_cli.NodeKeys, symbol, name, maxSupply, decimals, flags);
}
else
{
Expand Down
6 changes: 6 additions & 0 deletions Spook/Interop/NeoInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,12 @@ public static InteropTransaction MakeInteropTx(Logger logger, NeoTx tx, NeoAPI a
break;
}

if (entry.data == null || entry.data.Length == 0)
{
logger.Debug("Ignore tx, invalid data field: " + tx);
return emptyTx;
}

if (pos == 1)
{
amount = PBigInteger.FromUnsignedArray(entry.data, true);
Expand Down
14 changes: 14 additions & 0 deletions Spook/Modules/WalletModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,14 @@ private static VMObject ExecuteScript(byte[] script, ContractInterface abi, stri
throw new Exception("Script execution failed for: " + methodName);
}

private static bool FileExistsCaseSensitive(string filename)
{
string name = Path.GetDirectoryName(filename);

return name != null
&& Array.Exists(Directory.GetFiles(name), s => s == Path.GetFullPath(filename));
}

private static void DeployOrUpgrade(string[] args, SpookSettings settings, NexusAPI api, BigInteger minFee, bool isUpgrade)
{
if (args.Length != 1)
Expand All @@ -633,6 +641,11 @@ private static void DeployOrUpgrade(string[] args, SpookSettings settings, Nexus
throw new CommandException("Provided file does not exist");
}

if (!FileExistsCaseSensitive(fileName))
{
throw new CommandException("Provided file case does not match real file name case");
}

var extension = ScriptModule.ScriptExtension;

if (!fileName.EndsWith(extension))
Expand Down Expand Up @@ -680,6 +693,7 @@ private static void DeployOrUpgrade(string[] args, SpookSettings settings, Nexus
throw new CommandException("Failed to obtain nexus version via API");
}


bool isToken = ValidationUtils.IsValidTicker(contractName);
var availableFlags = Enum.GetValues(typeof(TokenFlags)).Cast<TokenFlags>().ToArray();

Expand Down
19 changes: 18 additions & 1 deletion Spook/Spook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class Spook : Runnable
private string _cryptoCompareAPIKey = null;
private Thread _tokenSwapperThread;

private List<PeerPort> _availablePorts = new List<PeerPort>();

public NexusAPI NexusAPI { get { return _nexusApi; } }
public Nexus Nexus { get { return _nexus; } }
public NeoAPI NeoAPI { get { return _neoAPI; } }
Expand Down Expand Up @@ -128,6 +130,21 @@ protected override void OnStart()
_mempool = SetupMempool();
}

if (Settings.Node.Mode != NodeMode.Proxy)
{
_availablePorts.Add(new PeerPort("sync", Settings.Node.NodePort));
}

if (Settings.Node.HasRpc)
{
_availablePorts.Add(new PeerPort("rpc", Settings.Node.RpcPort));
}

if (Settings.Node.HasRest)
{
_availablePorts.Add(new PeerPort("rest", Settings.Node.RestPort));
}

_peerCaps = SetupPeerCaps();

_node = SetupNode();
Expand Down Expand Up @@ -319,7 +336,7 @@ private Node SetupNode()
, _mempool
, _nodeKeys
, Settings.Node.NodeHost
, Settings.Node.NodePort
, _availablePorts
, _peerCaps
, Settings.Node.Seeds
, Logger);
Expand Down
12 changes: 6 additions & 6 deletions Spook/Utils/SpookUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static decimal GetNormalizedFee(FeeUrl[] fees)
results.Add(task.Result);
}

var median = GetMedian<decimal>(results.ToArray());
var median = GetMedian(results.ToArray());

return median;
}
Expand Down Expand Up @@ -206,12 +206,12 @@ public static decimal GetFee(FeeUrl feeObj)
return fee;
}

public static T GetMedian<T>(T[] sourceArray) where T : IComparable<T>
public static decimal GetMedian(decimal[] sourceArray)
{
if (sourceArray == null || sourceArray.Length == 0)
throw new ArgumentException("Median of empty array not defined.");

T[] sortedArray = sourceArray;
decimal[] sortedArray = sourceArray;
Array.Sort(sortedArray);

//get the median
Expand All @@ -222,10 +222,10 @@ public static T GetMedian<T>(T[] sourceArray) where T : IComparable<T>
return sortedArray[mid];
}

dynamic value1 = sortedArray[mid];
dynamic value2 = sortedArray[mid - 1];
decimal value1 = sortedArray[mid];
decimal value2 = sortedArray[mid - 1];

return (sortedArray[mid] + value2) * 0.5;
return (value1 + value2) * 0.5M;
}
}
}

0 comments on commit 34e8c7d

Please sign in to comment.