Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions AElf.All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.FeatureDisable.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.FeatureDisable.Core", "src\AElf.Kernel.FeatureDisable.Core\AElf.Kernel.FeatureDisable.Core.csproj", "{659A7C7A-44C9-424E-B4F6-D1D3656F7AD4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Sdk.CSharp.Internal", "src\AElf.Sdk.CSharp.Internal\AElf.Sdk.CSharp.Internal.csproj", "{21BC1437-BD34-4EBA-8F91-6A606782D06A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Sdk.CSharp.Spec", "src\AElf.Sdk.CSharp.Spec\AElf.Sdk.CSharp.Spec.csproj", "{D749B50E-34BF-43F1-AAAE-1306C490B7FE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1107,6 +1111,14 @@ Global
{659A7C7A-44C9-424E-B4F6-D1D3656F7AD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{659A7C7A-44C9-424E-B4F6-D1D3656F7AD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{659A7C7A-44C9-424E-B4F6-D1D3656F7AD4}.Release|Any CPU.Build.0 = Release|Any CPU
{21BC1437-BD34-4EBA-8F91-6A606782D06A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{21BC1437-BD34-4EBA-8F91-6A606782D06A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{21BC1437-BD34-4EBA-8F91-6A606782D06A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{21BC1437-BD34-4EBA-8F91-6A606782D06A}.Release|Any CPU.Build.0 = Release|Any CPU
{D749B50E-34BF-43F1-AAAE-1306C490B7FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D749B50E-34BF-43F1-AAAE-1306C490B7FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D749B50E-34BF-43F1-AAAE-1306C490B7FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D749B50E-34BF-43F1-AAAE-1306C490B7FE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1301,5 +1313,7 @@ Global
{A4ACE6D2-4CF8-4B52-93C9-BB8BEC0C098E} = {90B310B4-C2DB-419E-B5EE-97FA096B62CC}
{8C0D86A4-D1A7-4B61-AC44-755F5AC75D67} = {4E54480A-D155-43ED-9736-1A5BE7957211}
{659A7C7A-44C9-424E-B4F6-D1D3656F7AD4} = {90B310B4-C2DB-419E-B5EE-97FA096B62CC}
{21BC1437-BD34-4EBA-8F91-6A606782D06A} = {798BAA50-825B-4DD9-83E2-77A9EE6EBE09}
{D749B50E-34BF-43F1-AAAE-1306C490B7FE} = {798BAA50-825B-4DD9-83E2-77A9EE6EBE09}
EndGlobalSection
EndGlobal
22 changes: 22 additions & 0 deletions src/AElf.Sdk.CSharp.Internal/AElf.Sdk.CSharp.Internal.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props" />

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<PackageId>AElf.Sdk.CSharp.Internal</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<LangVersion>latest</LangVersion>
<Description>Types for the C# smart contract SDK.</Description>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Rebex.Elliptic.Ed25519" Version="1.2.1" >
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AElf.Sdk.CSharp.Spec\AElf.Sdk.CSharp.Spec.csproj" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions src/AElf.Sdk.CSharp.Internal/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("AElf.Sdk.CSharp")]
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using AElf.Sdk.CSharp.Spec;

namespace AElf.Sdk.CSharp;
namespace AElf.Sdk.CSharp.Internal;

public static class BuiltIns
internal class InternalBuiltIns : IBuiltIns
{
public static bool Ed25519Verify(byte[] signature, byte[] message, byte[] publicKey)
public bool Ed25519Verify(byte[] signature, byte[] message, byte[] publicKey)
{
try
{
Expand Down
9 changes: 9 additions & 0 deletions src/AElf.Sdk.CSharp.Spec/AElf.Sdk.CSharp.Spec.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
6 changes: 6 additions & 0 deletions src/AElf.Sdk.CSharp.Spec/IBuiltIns.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace AElf.Sdk.CSharp.Spec;

public interface IBuiltIns
{
bool Ed25519Verify(byte[] signature, byte[] message, byte[] publicKey);
}
16 changes: 7 additions & 9 deletions src/AElf.Sdk.CSharp/AElf.Sdk.CSharp.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props" />
<Import Project="..\..\common.props"/>

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -10,15 +10,13 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\AElf.Cryptography\AElf.Cryptography.csproj" />
<ProjectReference Include="..\AElf.CSharp.Core\AElf.CSharp.Core.csproj" />
<ProjectReference Include="..\AElf.Kernel.SmartContract.Shared\AElf.Kernel.SmartContract.Shared.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Rebex.Elliptic.Ed25519" Version="1.2.1" >
<ProjectReference Include="..\AElf.Cryptography\AElf.Cryptography.csproj"/>
<ProjectReference Include="..\AElf.CSharp.Core\AElf.CSharp.Core.csproj"/>
<ProjectReference Include="..\AElf.Kernel.SmartContract.Shared\AElf.Kernel.SmartContract.Shared.csproj"/>
<ProjectReference Include="..\AElf.Sdk.CSharp.Internal\AElf.Sdk.CSharp.Internal.csproj"/>
<ProjectReference Include="..\AElf.Sdk.CSharp.Spec\AElf.Sdk.CSharp.Spec.csproj">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ProjectReference>
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions src/AElf.Sdk.CSharp/CSharpSmartContractAbstract.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AElf.Kernel.SmartContract;
using AElf.Sdk.CSharp.Spec;
using AElf.Types;

namespace AElf.Sdk.CSharp;
Expand All @@ -11,6 +12,8 @@ public abstract class CSharpSmartContractAbstract : CSharpSmartContract
/// </summary>
public CSharpSmartContractContext Context { get; set; }

public IBuiltIns BuiltIns { get; internal set; }

internal abstract TransactionExecutingStateSet GetChanges();
internal abstract void Cleanup();

Expand Down
43 changes: 29 additions & 14 deletions src/AElf.Sdk.CSharp/CSharpSmartContractContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using AElf.Kernel.SmartContract;
using AElf.Sdk.CSharp.Internal;
using AElf.Sdk.CSharp.Spec;
using AElf.Types;
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
Expand All @@ -12,11 +14,14 @@ namespace AElf.Sdk.CSharp;
/// base class for smart contracts (Context property). It provides access to properties and methods useful for
/// implementing the logic in smart contracts.
/// </summary>
public class CSharpSmartContractContext : ISmartContractBridgeContext
public class CSharpSmartContractContext : ISmartContractBridgeContext, IBuiltIns
{
private IBuiltIns BuiltInsImplementation { get; }

public CSharpSmartContractContext(ISmartContractBridgeContext smartContractBridgeContextImplementation)
{
SmartContractBridgeContextImplementation = smartContractBridgeContextImplementation;
BuiltInsImplementation = new InternalBuiltIns();
}

public ISmartContractBridgeContext SmartContractBridgeContextImplementation { get; }
Expand Down Expand Up @@ -85,7 +90,7 @@ public void FireLogEvent(LogEvent logEvent)
/// The height of the block that contains the transaction before charging.
/// </summary>
public Transaction Transaction => SmartContractBridgeContextImplementation.Transaction;

/// <summary>
/// The time included in the current blocks header.
/// </summary>
Expand Down Expand Up @@ -148,7 +153,7 @@ public void DeployContract(Address address, SmartContractRegistration registrati
{
SmartContractBridgeContextImplementation.DeployContract(address, registration, name);
}

/// <summary>
/// Update a smart contract (only the genesis contract can call it).
/// </summary>
Expand All @@ -159,17 +164,21 @@ public void UpdateContract(Address address, SmartContractRegistration registrati
{
SmartContractBridgeContextImplementation.UpdateContract(address, registration, name);
}

public ContractInfoDto DeploySmartContract(Address address, SmartContractRegistration registration, Hash name)
{
return SmartContractBridgeContextImplementation.DeploySmartContract(address,registration,name);
return SmartContractBridgeContextImplementation.DeploySmartContract(address, registration, name);
}
public ContractInfoDto UpdateSmartContract(Address address, SmartContractRegistration registration, Hash name,string previousContractVersion)

public ContractInfoDto UpdateSmartContract(Address address, SmartContractRegistration registration, Hash name,
string previousContractVersion)
{
return SmartContractBridgeContextImplementation.UpdateSmartContract(address,registration,name,previousContractVersion);
return SmartContractBridgeContextImplementation.UpdateSmartContract(address, registration, name,
previousContractVersion);
}

public ContractVersionCheckDto CheckContractVersion(string previousContractVersion, SmartContractRegistration registration)
public ContractVersionCheckDto CheckContractVersion(string previousContractVersion,
SmartContractRegistration registration)
{
return SmartContractBridgeContextImplementation.CheckContractVersion(previousContractVersion, registration);
}
Expand Down Expand Up @@ -221,13 +230,14 @@ public void SendVirtualInline(Hash fromVirtualAddress, Address toAddress, string
SmartContractBridgeContextImplementation.SendVirtualInline(fromVirtualAddress, toAddress, methodName,
args);
}

public void SendVirtualInline(Hash fromVirtualAddress, Address toAddress, string methodName, ByteString args,bool logTransaction)

public void SendVirtualInline(Hash fromVirtualAddress, Address toAddress, string methodName, ByteString args,
bool logTransaction)
{
SmartContractBridgeContextImplementation.SendVirtualInline(fromVirtualAddress, toAddress, methodName,
args,logTransaction);
args, logTransaction);
}


/// <summary>
/// Sends a virtual inline transaction to another contract. This method is only available to system smart contract.
Expand All @@ -245,7 +255,7 @@ public void SendVirtualInlineBySystemContract(Hash fromVirtualAddress, Address t
SmartContractBridgeContextImplementation.SendVirtualInlineBySystemContract(fromVirtualAddress, toAddress,
methodName, args);
}

public void SendVirtualInlineBySystemContract(Hash fromVirtualAddress, Address toAddress, string methodName,
ByteString args, bool logTransaction)
{
Expand Down Expand Up @@ -386,9 +396,14 @@ public Address ConvertVirtualAddressToContractAddressWithContractHashName(Hash v
return SmartContractBridgeContextImplementation.ConvertVirtualAddressToContractAddressWithContractHashName(
virtualAddress);
}

public bool ECVrfVerify(byte[] pubKey, byte[] alpha, byte[] pi, out byte[] beta)
{
return SmartContractBridgeContextImplementation.ECVrfVerify(pubKey, alpha, pi, out beta);
}

public bool Ed25519Verify(byte[] signature, byte[] message, byte[] publicKey)
{
return BuiltInsImplementation.Ed25519Verify(signature, message, publicKey);
}
}