Skip to content

Commit

Permalink
Merge branch 'master' into organize-events
Browse files Browse the repository at this point in the history
  • Loading branch information
NGDAdmin authored Jun 18, 2024
2 parents e0be309 + 379ce75 commit 94e22b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/Plugins/RpcServer/RpcServer.Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected virtual JToken GetBlock(JArray _params)
}
else
{
UInt256 hash = UInt256.Parse(key.AsString());
UInt256 hash = Result.Ok_Or(() => UInt256.Parse(key.AsString()), RpcError.InvalidParams.WithData($"Invalid block hash {_params[0]}"));
block = NativeContract.Ledger.GetBlock(snapshot, hash);
}
block.NotNull_Or(RpcError.UnknownBlock);
Expand Down Expand Up @@ -98,7 +98,7 @@ protected virtual JToken GetBlockHeader(JArray _params)
}
else
{
UInt256 hash = UInt256.Parse(key.AsString());
UInt256 hash = Result.Ok_Or(() => UInt256.Parse(key.AsString()), RpcError.InvalidParams.WithData($"Invalid block hash {_params[0]}"));
header = NativeContract.Ledger.GetHeader(snapshot, hash).NotNull_Or(RpcError.UnknownBlock);
}
if (verbose)
Expand All @@ -123,7 +123,7 @@ protected virtual JToken GetContractState(JArray _params)
return contractState.NotNull_Or(RpcError.UnknownContract).ToJson();
}

var scriptHash = ToScriptHash(_params[0].AsString());
var scriptHash = Result.Ok_Or(() => ToScriptHash(_params[0].AsString()), RpcError.InvalidParams.WithData($"Invalid contract hash {_params[0]}"));
var contract = NativeContract.ContractManagement.GetContract(system.StoreView, scriptHash);
return contract.NotNull_Or(RpcError.UnknownContract).ToJson();
}
Expand Down Expand Up @@ -185,7 +185,7 @@ protected virtual JToken GetStorage(JArray _params)
using var snapshot = system.GetSnapshot();
if (!int.TryParse(_params[0].AsString(), out int id))
{
UInt160 hash = UInt160.Parse(_params[0].AsString());
UInt160 hash = Result.Ok_Or(() => UInt160.Parse(_params[0].AsString()), RpcError.InvalidParams.WithData($"Invalid contract hash {_params[0]}"));
ContractState contract = NativeContract.ContractManagement.GetContract(snapshot, hash).NotNull_Or(RpcError.UnknownContract);
id = contract.Id;
}
Expand All @@ -204,12 +204,12 @@ protected virtual JToken FindStorage(JArray _params)
using var snapshot = system.GetSnapshot();
if (!int.TryParse(_params[0].AsString(), out int id))
{
UInt160 hash = UInt160.Parse(_params[0].AsString());
UInt160 hash = Result.Ok_Or(() => UInt160.Parse(_params[0].AsString()), RpcError.InvalidParams.WithData($"Invalid contract hash {_params[0]}"));
ContractState contract = NativeContract.ContractManagement.GetContract(snapshot, hash).NotNull_Or(RpcError.UnknownContract);
id = contract.Id;
}

byte[] prefix = Convert.FromBase64String(_params[1].AsString());
byte[] prefix = Result.Ok_Or(() => Convert.FromBase64String(_params[1].AsString()), RpcError.InvalidParams.WithData($"Invalid Base64 string{_params[1]}"));
byte[] prefix_key = StorageKey.CreateSearchPrefix(id, prefix);

if (!int.TryParse(_params[2].AsString(), out int start))
Expand Down
4 changes: 2 additions & 2 deletions src/Plugins/RpcServer/RpcServer.Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected virtual JToken GetNewAddress(JArray _params)
protected virtual JToken GetWalletBalance(JArray _params)
{
CheckWallet();
UInt160 asset_id = UInt160.Parse(_params[0].AsString());
UInt160 asset_id = Result.Ok_Or(() => UInt160.Parse(_params[0].AsString()), RpcError.InvalidParams.WithData($"Invalid asset id: {_params[0]}"));
JObject json = new();
json["balance"] = wallet.GetAvailable(system.StoreView, asset_id).Value.ToString();
return json;
Expand Down Expand Up @@ -193,7 +193,7 @@ private void ProcessInvokeWithWallet(JObject result, Signer[] signers = null)
protected virtual JToken SendFrom(JArray _params)
{
CheckWallet();
UInt160 assetId = UInt160.Parse(_params[0].AsString());
UInt160 assetId = Result.Ok_Or(() => UInt160.Parse(_params[0].AsString()), RpcError.InvalidParams.WithData($"Invalid asset id: {_params[0]}"));
UInt160 from = AddressToScriptHash(_params[1].AsString(), system.Settings.AddressVersion);
UInt160 to = AddressToScriptHash(_params[2].AsString(), system.Settings.AddressVersion);
using var snapshot = system.GetSnapshot();
Expand Down

0 comments on commit 94e22b7

Please sign in to comment.