Skip to content

Commit

Permalink
update oracleservice wallet (#473)
Browse files Browse the repository at this point in the history
* update walelt

* redefine walletProvider

* syc neo

* Clean settings

* check wallet if null

* Update OracleService.cs

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Erik Zhang <erik@neo.org>
  • Loading branch information
3 people authored Jan 19, 2021
1 parent 5a060a9 commit fd52f21
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-CI01159" />
<PackageReference Include="Neo" Version="3.0.0-CI01161" />
</ItemGroup>

</Project>
24 changes: 8 additions & 16 deletions src/OracleService/OracleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
using Neo.SmartContract;
using Neo.SmartContract.Manifest;
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.Wallets;
using Neo.Wallets.NEP6;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand All @@ -32,7 +32,7 @@ public class OracleService : Plugin, IPersistencePlugin
{
private const int RefreshInterval = 1000 * 60 * 3;

private NEP6Wallet wallet;
private Wallet wallet;
private readonly ConcurrentDictionary<ulong, OracleTask> pendingQueue = new ConcurrentDictionary<ulong, OracleTask>();
private readonly ConcurrentDictionary<ulong, DateTime> finishedCache = new ConcurrentDictionary<ulong, DateTime>();
private Timer timer;
Expand Down Expand Up @@ -73,21 +73,12 @@ public override void Dispose()
private void OnStart()
{
if (started) return;
string password = GetService<ConsoleServiceBase>().ReadUserInput("password", true);
if (password.Length == 0)
{
Console.WriteLine("Cancelled");
return;
}

wallet = new NEP6Wallet(Settings.Default.Wallet);
try
{
wallet.Unlock(password);
}
catch (System.Security.Cryptography.CryptographicException)
wallet = GetService<IWalletProvider>().GetWallet();

if (wallet is null)
{
Console.WriteLine($"Failed to open wallet");
Console.WriteLine("Please open wallet first!");
return;
}

Expand Down Expand Up @@ -341,7 +332,8 @@ public static Transaction CreateResponseTx(StoreView snapshot, OracleRequest req

var oracleContract = NativeContract.ContractManagement.GetContract(snapshot, NativeContract.Oracle.Hash);
var engine = ApplicationEngine.Create(TriggerType.Verification, tx, snapshot.Clone());
engine.LoadContract(oracleContract, "verify", CallFlags.None, true);
ContractMethodDescriptor md = oracleContract.Manifest.Abi.GetMethod("verify", -1);
engine.LoadContract(oracleContract, md, CallFlags.None);
engine.Push("verify");
if (engine.Execute() != VMState.HALT) return null;
tx.NetworkFee += engine.GasConsumed;
Expand Down
1 change: 0 additions & 1 deletion src/OracleService/OracleService/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"PluginConfiguration": {
"Nodes": [],
"Wallet": "",
"MaxTaskTimeout": 432000000,
"AllowPrivateHost": false,
"AllowedContentTypes": [ "application/json" ],
Expand Down
2 changes: 0 additions & 2 deletions src/OracleService/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public HttpsSettings(IConfigurationSection section)
class Settings
{
public string[] Nodes { get; }
public string Wallet { get; }
public TimeSpan MaxTaskTimeout { get; }
public bool AllowPrivateHost { get; }
public string[] AllowedContentTypes { get; }
Expand All @@ -28,7 +27,6 @@ class Settings
private Settings(IConfigurationSection section)
{
Nodes = section.GetSection("Nodes").GetChildren().Select(p => p.Get<string>()).ToArray();
Wallet = section.GetValue<string>("Wallet");
MaxTaskTimeout = TimeSpan.FromMilliseconds(section.GetValue("MaxTaskTimeout", 432000000));
AllowPrivateHost = section.GetValue("AllowPrivateHost", false);
AllowedContentTypes = section.GetSection("AllowedContentTypes").GetChildren().Select(p => p.Get<string>()).ToArray();
Expand Down

0 comments on commit fd52f21

Please sign in to comment.