-
Notifications
You must be signed in to change notification settings - Fork 1k
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 Core Style] update smartcontract struct and name #3488
base: master
Are you sure you want to change the base?
Changes from all commits
4996008
4dac770
40d7c8e
26a1082
b3e2d9e
8ff5417
26fbd30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -13,10 +13,12 @@ | |||||
using Neo.Json; | ||||||
using Neo.Persistence; | ||||||
using Neo.SmartContract.Native; | ||||||
using System; | ||||||
using System.IO; | ||||||
|
||||||
namespace Neo.Network.P2P.Payloads | ||||||
{ | ||||||
[Obsolete("Use ConflictsAttribute instead")] | ||||||
public class Conflicts : TransactionAttribute | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before remove maybe is easier to mantain if we share the code
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shargon thats what i said here #3488 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
But code is already there, keep this pr this way as much easier isn't it~~~~ |
||||||
{ | ||||||
/// <summary> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// ConflictsAttribute.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 Neo.IO; | ||
using Neo.Json; | ||
using Neo.Persistence; | ||
using Neo.SmartContract.Native; | ||
using System.IO; | ||
|
||
namespace Neo.Network.P2P.Payloads | ||
{ | ||
public class ConflictsAttribute : TransactionAttribute | ||
{ | ||
/// <summary> | ||
/// Indicates the conflict transaction hash. | ||
/// </summary> | ||
public UInt256 Hash; | ||
|
||
public override TransactionAttributeType Type => TransactionAttributeType.Conflicts; | ||
|
||
public override bool AllowMultiple => true; | ||
|
||
public override int Size => base.Size + Hash.Size; | ||
|
||
protected override void DeserializeWithoutType(ref MemoryReader reader) | ||
{ | ||
Hash = reader.ReadSerializable<UInt256>(); | ||
} | ||
|
||
protected override void SerializeWithoutType(BinaryWriter writer) | ||
{ | ||
writer.Write(Hash); | ||
} | ||
|
||
public override JObject ToJson() | ||
{ | ||
JObject json = base.ToJson(); | ||
json["hash"] = Hash.ToString(); | ||
return json; | ||
} | ||
|
||
public override bool Verify(DataCache snapshot, Transaction tx) | ||
{ | ||
// Only check if conflicting transaction is on chain. It's OK if the | ||
// conflicting transaction was in the Conflicts attribute of some other | ||
// on-chain transaction. | ||
return !NativeContract.Ledger.ContainsTransaction(snapshot, Hash); | ||
} | ||
|
||
public override long CalculateNetworkFee(DataCache snapshot, Transaction tx) | ||
{ | ||
return tx.Signers.Length * base.CalculateNetworkFee(snapshot, tx); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,12 @@ | |
using Neo.Json; | ||
using Neo.Persistence; | ||
using Neo.SmartContract.Native; | ||
using System; | ||
using System.IO; | ||
|
||
namespace Neo.Network.P2P.Payloads | ||
{ | ||
[Obsolete("Use NotValidBeforeAttribute instead")] | ||
public class NotValidBefore : TransactionAttribute | ||
{ | ||
/// <summary> | ||
|
@@ -29,7 +31,7 @@ public class NotValidBefore : TransactionAttribute | |
public override bool AllowMultiple => false; | ||
|
||
public override int Size => base.Size + | ||
sizeof(uint); // Height. | ||
sizeof(uint); // Height. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Useless change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this may cause by my dotnet format. |
||
|
||
protected override void DeserializeWithoutType(ref MemoryReader reader) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// NotValidBeforeAttribute.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 Neo.IO; | ||
using Neo.Json; | ||
using Neo.Persistence; | ||
using Neo.SmartContract.Native; | ||
using System.IO; | ||
|
||
namespace Neo.Network.P2P.Payloads | ||
{ | ||
public class NotValidBeforeAttribute : TransactionAttribute | ||
{ | ||
/// <summary> | ||
/// Indicates that the transaction is not valid before this height. | ||
/// </summary> | ||
public uint Height; | ||
|
||
public override TransactionAttributeType Type => TransactionAttributeType.NotValidBefore; | ||
|
||
public override bool AllowMultiple => false; | ||
|
||
public override int Size => base.Size + | ||
sizeof(uint); // Height. | ||
|
||
protected override void DeserializeWithoutType(ref MemoryReader reader) | ||
{ | ||
Height = reader.ReadUInt32(); | ||
} | ||
|
||
protected override void SerializeWithoutType(BinaryWriter writer) | ||
{ | ||
writer.Write(Height); | ||
} | ||
|
||
public override JObject ToJson() | ||
{ | ||
JObject json = base.ToJson(); | ||
json["height"] = Height; | ||
return json; | ||
} | ||
|
||
public override bool Verify(DataCache snapshot, Transaction tx) | ||
{ | ||
var block_height = NativeContract.Ledger.CurrentIndex(snapshot); | ||
return block_height >= Height; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// OracleResponseAttribute.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 Neo.IO; | ||
using Neo.Json; | ||
using Neo.Persistence; | ||
using Neo.SmartContract; | ||
using Neo.SmartContract.Native; | ||
using Neo.VM; | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace Neo.Network.P2P.Payloads | ||
{ | ||
/// <summary> | ||
/// Indicates that the transaction is an oracle response. | ||
/// </summary> | ||
public class OracleResponseAttribute : TransactionAttribute | ||
{ | ||
/// <summary> | ||
/// Indicates the maximum size of the <see cref="Result"/> field. | ||
/// </summary> | ||
public const int MaxResultSize = ushort.MaxValue; | ||
|
||
/// <summary> | ||
/// Represents the fixed value of the <see cref="Transaction.Script"/> field of the oracle responding transaction. | ||
/// </summary> | ||
public static readonly byte[] FixedScript; | ||
|
||
/// <summary> | ||
/// The ID of the oracle request. | ||
/// </summary> | ||
public ulong Id; | ||
|
||
/// <summary> | ||
/// The response code for the oracle request. | ||
/// </summary> | ||
public OracleResponseCode Code; | ||
|
||
/// <summary> | ||
/// The result for the oracle request. | ||
/// </summary> | ||
public ReadOnlyMemory<byte> Result; | ||
|
||
public override TransactionAttributeType Type => TransactionAttributeType.OracleResponse; | ||
public override bool AllowMultiple => false; | ||
|
||
public override int Size => base.Size + | ||
sizeof(ulong) + //Id | ||
sizeof(OracleResponseCode) + //ResponseCode | ||
Result.GetVarSize(); //Result | ||
|
||
static OracleResponseAttribute() | ||
{ | ||
using ScriptBuilder sb = new(); | ||
sb.EmitDynamicCall(NativeContract.Oracle.Hash, "finish"); | ||
FixedScript = sb.ToArray(); | ||
} | ||
|
||
protected override void DeserializeWithoutType(ref MemoryReader reader) | ||
{ | ||
Id = reader.ReadUInt64(); | ||
Code = (OracleResponseCode)reader.ReadByte(); | ||
if (!Enum.IsDefined(typeof(OracleResponseCode), Code)) | ||
throw new FormatException(); | ||
Result = reader.ReadVarMemory(MaxResultSize); | ||
if (Code != OracleResponseCode.Success && Result.Length > 0) | ||
throw new FormatException(); | ||
} | ||
|
||
protected override void SerializeWithoutType(BinaryWriter writer) | ||
{ | ||
writer.Write(Id); | ||
writer.Write((byte)Code); | ||
writer.WriteVarBytes(Result.Span); | ||
} | ||
|
||
public override JObject ToJson() | ||
{ | ||
JObject json = base.ToJson(); | ||
json["id"] = Id; | ||
json["code"] = Code; | ||
json["result"] = Convert.ToBase64String(Result.Span); | ||
return json; | ||
} | ||
|
||
public override bool Verify(DataCache snapshot, Transaction tx) | ||
{ | ||
if (tx.Signers.Any(p => p.Scopes != WitnessScope.None)) return false; | ||
if (!tx.Script.Span.SequenceEqual(FixedScript)) return false; | ||
OracleRequest request = NativeContract.Oracle.GetRequest(snapshot, Id); | ||
if (request is null) return false; | ||
if (tx.NetworkFee + tx.SystemFee != request.GasForResponse) return false; | ||
UInt160 oracleAccount = Contract.GetBFTAddress(NativeContract.RoleManagement.GetDesignatedByRole(snapshot, Role.Oracle, NativeContract.Ledger.CurrentIndex(snapshot) + 1)); | ||
return tx.Signers.Any(p => p.Account.Equals(oracleAccount)); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create an issue to remove this obsolete code. This issue should be included into next release.