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

[Neo Plugin RPCServer] Rpc parameters. Part I #3457

Merged
merged 21 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/Plugins/RpcServer/Model/BlockHashOrIndex.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// BlockHashOrIndex.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

namespace Neo.Plugins.RpcServer.Model;

public class BlockHashOrIndex
cschuchardt88 marked this conversation as resolved.
Show resolved Hide resolved
{
private readonly object _value;

public BlockHashOrIndex(uint index)
{
_value = index;
}

public BlockHashOrIndex(UInt256 hash)
{
_value = hash;
}

public bool IsIndex => _value is uint;
public bool IsHash => _value is UInt256;
cschuchardt88 marked this conversation as resolved.
Show resolved Hide resolved

public uint AsIndex()
{
if (_value is uint intValue)
return intValue;
throw new RpcException(RpcError.InvalidParams.WithData($"Value {_value} is not a valid block index"));
}

public UInt256 AsHash()
{
if (_value is UInt256 hash)
return hash;
throw new RpcException(RpcError.InvalidParams.WithData($"Value {_value} is not a valid block hash"));
}
}
44 changes: 44 additions & 0 deletions src/Plugins/RpcServer/Model/ContractHashOrId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// ContractHashOrId.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

namespace Neo.Plugins.RpcServer.Model;

public class ContractHashOrId
{
private readonly object _value;

public ContractHashOrId(int id)
{
_value = id;
}

public ContractHashOrId(UInt160 hash)
{
_value = hash;
}

public bool IsId => _value is int;
public bool IsHash => _value is UInt160;

public int AsId()
{
if (_value is int intValue)
return intValue;
throw new RpcException(RpcError.InvalidParams.WithData($"Value {_value} is not a valid contract id"));
}

public UInt160 AsHash()
{
if (_value is UInt160 hash)
return hash;
throw new RpcException(RpcError.InvalidParams.WithData($"Value {_value} is not a valid contract hash"));
}
}
20 changes: 20 additions & 0 deletions src/Plugins/RpcServer/RpcMethodWithParamsAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// RpcMethodWithParamsAttribute.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using System;

namespace Neo.Plugins.RpcServer;

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class RpcMethodWithParamsAttribute : Attribute
{
public string Name { get; set; }
}
Loading
Loading