Skip to content

Commit

Permalink
Add: make storage attribute also work (#841)
Browse files Browse the repository at this point in the history
* make storage attribute also work

* use stored as suggested
  • Loading branch information
Jim8y authored Dec 19, 2023
1 parent e51c648 commit 93003c1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Neo.Compiler.CSharp/MethodConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ private void ConvertNoBody(AccessorDeclarationSyntax syntax)
{
_callingConvention = CallingConvention.Cdecl;
IPropertySymbol property = (IPropertySymbol)Symbol.AssociatedSymbol!;
AttributeData? attribute = property.GetAttributes().FirstOrDefault(p => p.AttributeClass!.Name == nameof(StorageBackedAttribute));
AttributeData? attribute = property.GetAttributes().FirstOrDefault(p => p.AttributeClass!.Name == nameof(StoredAttribute));
using (InsertSequencePoint(syntax))
{
_inline = attribute is null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (C) 2015-2023 The Neo Project.
//
// The Neo.SmartContract.Framework is free software distributed under the MIT
// software license, see the accompanying file LICENSE in the main directory
// of the project or http://www.opensource.org/licenses/mit-license.php
//
// The Neo.SmartContract.Framework is free software distributed under the MIT
// software license, see the accompanying file LICENSE in the main directory
// of the project 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.

Expand All @@ -15,23 +15,23 @@
namespace Neo.SmartContract.Framework.Attributes
{
[AttributeUsage(AttributeTargets.Property, Inherited = false)]
public class StorageBackedAttribute : Attribute
public class StoredAttribute : Attribute
{
/// <summary>
/// The property will be backed in the storage using the specific key using the property name as storage key
/// </summary>
public StorageBackedAttribute() { }
public StoredAttribute() { }

/// <summary>
/// The property will be backed in the storage using the specific key
/// </summary>
/// <param name="storageKey">Storage key</param>
public StorageBackedAttribute(byte storageKey) { }
public StoredAttribute(byte storageKey) { }

/// <summary>
/// The property will be backed in the storage using the specific key
/// </summary>
/// <param name="storageKey">Storage key</param>
public StorageBackedAttribute(string storageKey) { }
public StoredAttribute(string storageKey) { }
}
}
12 changes: 6 additions & 6 deletions src/Neo.SmartContract.Framework/TokenContract.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (C) 2015-2023 The Neo Project.
//
// The Neo.SmartContract.Framework is free software distributed under the MIT
// software license, see the accompanying file LICENSE in the main directory
// of the project or http://www.opensource.org/licenses/mit-license.php
//
// The Neo.SmartContract.Framework is free software distributed under the MIT
// software license, see the accompanying file LICENSE in the main directory
// of the project 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.

Expand All @@ -24,7 +24,7 @@ public abstract class TokenContract : SmartContract

public abstract byte Decimals { [Safe] get; }

[StorageBacked(Prefix_TotalSupply)]
[Stored(Prefix_TotalSupply)]
public static BigInteger TotalSupply { [Safe] get; protected set; }

[Safe]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void Init()
var snapshot = system.GetSnapshot().CreateSnapshot();

_engine = new TestEngine(snapshot: snapshot);
Assert.IsTrue(_engine.AddEntryScript("./TestClasses/Contract_StorageBacked.cs").Success);
Assert.IsTrue(_engine.AddEntryScript("./TestClasses/Contract_Stored.cs").Success);
snapshot.ContractAdd(new ContractState()
{
Id = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Contract_StorageBacked : SmartContract
{
// Test non-static

[StorageBacked]
[Stored]
public BigInteger WithoutConstructor { [Safe] get; protected set; }

public void putWithoutConstructor(BigInteger value)
Expand All @@ -22,7 +22,7 @@ public void putWithoutConstructor(BigInteger value)

// ---

[StorageBacked(0x01)]
[Stored(0x01)]
public static BigInteger WithKey { [Safe] get; protected set; }

public static void putWithKey(BigInteger value)
Expand All @@ -35,7 +35,7 @@ public static void putWithKey(BigInteger value)

// ---

[StorageBacked("testMe")]
[Stored("testMe")]
public static BigInteger WithString { [Safe] get; protected set; }

public static void putWithString(BigInteger value)
Expand All @@ -47,14 +47,14 @@ public static void putWithString(BigInteger value)
public static BigInteger getWithString() => WithString;


[StorageBacked]
[Stored]
public static BigInteger PrivateGetterPublicSetter { [Safe] private get; set; }

[Safe]
public static BigInteger getPrivateGetterPublicSetter() => PrivateGetterPublicSetter;


[StorageBacked]
[Stored]
public BigInteger NonStaticPrivateGetterPublicSetter { [Safe] private get; set; }

[Safe]
Expand Down

0 comments on commit 93003c1

Please sign in to comment.