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

[Framwork Add]Add examples #931

Merged
merged 36 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
21f7419
add examples and ease contract implementation
Jim8y Feb 19, 2024
2c0da4e
optimize the code
Jim8y Feb 21, 2024
6f13c68
Merge branch 'master' into add-examples
Jim8y Feb 21, 2024
c75cff8
Merge branch 'master' into add-examples
Jim8y Feb 21, 2024
e1af5f8
Merge branch 'master' into add-examples
Jim8y Feb 22, 2024
40ea594
Merge branch 'add-examples' of github.com:Jim8y/neo-devpack-dotnet in…
Jim8y Feb 24, 2024
1b9d962
Merge branch 'master' into add-examples
Jim8y Feb 25, 2024
24555e2
Delete src/Neo.SmartContract.Template/templates/neocontract/Contract1.cs
shargon Feb 25, 2024
09f2785
Merge branch 'master' into add-examples
Jim8y Feb 26, 2024
27e671a
Merge branch 'add-examples' of github.com:Jim8y/neo-devpack-dotnet in…
Jim8y Feb 26, 2024
b6b6e94
Merge branch 'master' into add-examples
Jim8y Feb 26, 2024
b6d6c1e
fix coverage issue
Jim8y Feb 26, 2024
725a783
Merge branch 'master' into add-examples
Jim8y Feb 26, 2024
d61e4ff
Update tests/Neo.SmartContract.Framework.TestContracts/Contract_Suppo…
shargon Feb 26, 2024
28c829d
remove conflict
Jim8y Feb 26, 2024
5954bee
Merge branch 'master' into add-examples
Jim8y Feb 26, 2024
c0f5006
Merge branch 'master' into add-examples
Jim8y Feb 26, 2024
8fe9173
Merge branch 'master' into add-examples
Jim8y Feb 26, 2024
7a4d438
Merge branch 'master' into add-examples
Jim8y Feb 26, 2024
38aad3c
Merge branch 'add-examples'
Jim8y Feb 27, 2024
be6cdbf
Merge branch 'master' into add-examples
Jim8y Feb 27, 2024
f0c1d6e
Update tests/Neo.SmartContract.Template.UnitTests/templates/neocontra…
shargon Feb 27, 2024
79f01a3
Update src/Neo.SmartContract.Framework/Interfaces/INEP11Payment.cs
Jim8y Feb 27, 2024
528d263
fix url
Jim8y Feb 27, 2024
6dc7e12
Merge branch 'add-examples' of github.com:Jim8y/neo-devpack-dotnet in…
Jim8y Feb 27, 2024
39d28f9
fix name
Jim8y Feb 27, 2024
c3fd99b
remove extra file
Jim8y Feb 27, 2024
862a2a0
revert
Jim8y Feb 27, 2024
0aaa6dc
Merge branch 'master' into add-examples
Jim8y Feb 28, 2024
c1db8c8
Merge branch 'master' into add-examples
shargon Feb 28, 2024
ae15f04
Update TransferContract.cs
shargon Feb 28, 2024
a0fd5c1
Some fixes & clean code
shargon Feb 28, 2024
933d6fa
clean
shargon Feb 28, 2024
330ff6a
Clean and comment
shargon Feb 28, 2024
4a7ba49
clean
shargon Feb 28, 2024
af5f866
Remove todo
shargon Feb 28, 2024
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
30 changes: 30 additions & 0 deletions examples/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<Copyright>2024 The SharpNeo Examples Project</Copyright>
<VersionPrefix>3.6.2</VersionPrefix>
<TargetFramework>net7.0</TargetFramework>
<Authors>The SharpNeo Project</Authors>
<PackageIcon>neo.png</PackageIcon>
<PackageProjectUrl>https://github.com/neo-project/neo-devpack-dotnet/examples</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/neo-project/neo-devpack-dotnet.git</RepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Company>The Neo N3 Contract Examples Project</Company>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Neo.SmartContract.Framework\Neo.SmartContract.Framework.csproj" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works with the current compiler?

Copy link
Contributor Author

@Jim8y Jim8y Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not compiled, just syntax. Compile the example everytime is meaningless.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, in public Compilation GetCompilation(string csproj) we don't read the Directory.Build.props, maybe we should do it, (not related to this pr)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emmmm, to be honest, i never thought we will run into this situation

</ItemGroup>

<!-- <Target Name="PostBuild" AfterTargets="PostBuildEvent">-->
<!-- <Exec Command="dotnet nccs &quot;$(MSBuildProjectFile)&quot;" />-->
<!-- </Target>-->
</Project>
39 changes: 39 additions & 0 deletions examples/Example.SmartContract.ContractCall/ContractCall.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// ContractCall.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.SmartContract.Framework;
using Neo.SmartContract.Framework.Attributes;
using Neo.SmartContract.Framework.Services;
using System.ComponentModel;
using System.Numerics;

namespace ContractCall;

[DisplayName("SampleContractCall")]
[ContractAuthor("core-dev")]
[ContractEmail("[email protected]")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its example. should be fine.

[ContractVersion("0.0.1")]
[ContractDescription("A sample contract to demonstrate how to call a contract")]
[ContractSourceCode("https://github.com/neo-project/neo-devpack-dotnet/tree/master/examples/")]
public class SampleContractCall : SmartContract

Check warning on line 26 in examples/Example.SmartContract.ContractCall/ContractCall.cs

View workflow job for this annotation

GitHub Actions / Test

Missing XML comment for publicly visible type or member 'SampleContractCall'
{
[Hash160("0x13a83e059c2eedd5157b766d3357bc826810905e")]
private static readonly UInt160 DummyTarget;

Check warning on line 29 in examples/Example.SmartContract.ContractCall/ContractCall.cs

View workflow job for this annotation

GitHub Actions / Test

Non-nullable field 'DummyTarget' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 29 in examples/Example.SmartContract.ContractCall/ContractCall.cs

View workflow job for this annotation

GitHub Actions / Test

Field 'SampleContractCall.DummyTarget' is never assigned to, and will always have its default value null

public static void onNEP17Payment(UInt160 from, BigInteger amount, BigInteger data)

Check warning on line 31 in examples/Example.SmartContract.ContractCall/ContractCall.cs

View workflow job for this annotation

GitHub Actions / Test

Missing XML comment for publicly visible type or member 'SampleContractCall.onNEP17Payment(UInt160, BigInteger, BigInteger)'
{
if (!data.Equals(123)) return;
UInt160 @this = Runtime.ExecutingScriptHash;
UInt160 tokenHash = Runtime.CallingScriptHash;
BigInteger balanceOf = (BigInteger)Contract.Call(tokenHash, "balanceOf", CallFlags.All, @this);
Contract.Call(DummyTarget, "dummyMethod", CallFlags.All, @this, tokenHash, balanceOf);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>ContractCall</RootNamespace>
</PropertyGroup>

</Project>
40 changes: 40 additions & 0 deletions examples/Example.SmartContract.Event/Event.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// Event.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.SmartContract.Framework;
using Neo.SmartContract.Framework.Attributes;
using System;
using System.ComponentModel;
using System.Numerics;

namespace Event;

[DisplayName("SampleEvent")]
[ContractAuthor("code-dev", "[email protected]")]
[ContractDescription("A sample contract that demonstrates how to use Events")]
[ContractVersion("0.0.1")]
[ContractSourceCode("https://github.com/neo-project/neo-devpack-dotnet/tree/master/examples/")]
[ContractPermission(Permission.WildCard, Method.WildCard)]
public class SampleEvent : SmartContract

Check warning on line 26 in examples/Example.SmartContract.Event/Event.cs

View workflow job for this annotation

GitHub Actions / Test

Missing XML comment for publicly visible type or member 'SampleEvent'
{
[DisplayName("new_event_name")]
public static event Action<byte[], string, BigInteger> event_name;

Check warning on line 29 in examples/Example.SmartContract.Event/Event.cs

View workflow job for this annotation

GitHub Actions / Test

Non-nullable event 'event_name' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

Check warning on line 29 in examples/Example.SmartContract.Event/Event.cs

View workflow job for this annotation

GitHub Actions / Test

Missing XML comment for publicly visible type or member 'SampleEvent.event_name'

public static event Action<byte[], BigInteger> event2;

Check warning on line 31 in examples/Example.SmartContract.Event/Event.cs

View workflow job for this annotation

GitHub Actions / Test

Non-nullable event 'event2' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

Check warning on line 31 in examples/Example.SmartContract.Event/Event.cs

View workflow job for this annotation

GitHub Actions / Test

Missing XML comment for publicly visible type or member 'SampleEvent.event2'

public static bool Main()

Check warning on line 33 in examples/Example.SmartContract.Event/Event.cs

View workflow job for this annotation

GitHub Actions / Test

Missing XML comment for publicly visible type or member 'SampleEvent.Main()'
{
byte[] ba = new byte[] { 0x01, 0x02, 0x03 };
event_name(ba, "oi", 10); // will Example.SmartContract.Runtime.Notify: 'new_event_name', '\x01\x02\x03', 'oi', 10
event2(ba, 50); // will Example.SmartContract.Runtime.Notify: 'event2', '\x01\x02\x03', '\x32'
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>Event</RootNamespace>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>Exception</RootNamespace>
</PropertyGroup>

</Project>
Loading
Loading