-
Notifications
You must be signed in to change notification settings - Fork 3
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
Feature: Added aelf-samples submodule #52
Open
vasmohi
wants to merge
5
commits into
master
Choose a base branch
from
feature/aelf-samples-submodule
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,601
−1
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ff5d6cf
feat: Added aelf-samples submodule
vasmohi 3dd98ba
feat: Added ToDo, TicTacToe & ExpenseTracker contracts to playground
vasmohi f608fe8
Added templates configs for ToDo, TicTacToe & ExpenseTracker
vasmohi 92780ac
feat: Added workflows for staging & prod to publish aelf-samples
vasmohi a653202
fix: Changed source of templates to aelf-sample and removed aelf-samp…
vasmohi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
on: | ||
push: | ||
branches: | ||
- release/aelf-samples/* | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
env: | ||
WORKING_DIRECTORY: aelf-samples | ||
environment: staging | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: '7.0.*' # Change this to the .NET version you're using | ||
|
||
- name: Read version from Version.props | ||
working-directory: ${{ env.WORKING_DIRECTORY }} | ||
run: | | ||
version=$(grep -oP '<Version>\K[^<]+' Version.props) | ||
echo "VERSION=$version-rc.${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV | ||
|
||
- name: Pack | ||
working-directory: ${{ env.WORKING_DIRECTORY }} | ||
run: dotnet pack --configuration Release --output nupkgs /p:Version=$VERSION | ||
|
||
- name: Publish NuGet packages | ||
working-directory: ${{ env.WORKING_DIRECTORY }} | ||
run: | | ||
dotnet nuget push "nupkgs/*.nupkg" --api-key ${{ secrets.TEST_AELF_SAMPLES_NUGET_API_KEY }} --source ${{ vars.TEST_AELF_SAMPLES_NUGET_SOURCE_URL }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "aelf-samples"] | ||
path = aelf-samples | ||
url = https://github.com/AElfProject/aelf-samples.git |
Submodule aelf-samples
added at
6e8355
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
21 changes: 21 additions & 0 deletions
21
templates/ExpenseTrackerContract/.template.config/template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/template", | ||
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. All these should be added into aelf-samples repo to maintain consistency 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. Added to aelf-samples |
||
"author": "AElf", | ||
"classifications": [ | ||
"AElf/SmartContract" | ||
], | ||
"identity": "AElf.Contract.ExpenseTracker.Template", | ||
"name": "AElf Contract ExpenseTracker Template", | ||
"shortName": "aelf-expense-tracker", | ||
"tags": { | ||
"language": "C#", | ||
"type": "project" | ||
}, | ||
"sourceName": "ExpenseTracker", | ||
"symbols": { | ||
"NamespacePath": { | ||
"type": "parameter", | ||
"replaces": "AElf.Contracts.ExpenseTracker" | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using Google.Protobuf.WellKnownTypes; | ||
using System.Collections.Generic; | ||
|
||
namespace AElf.Contracts.ExpenseTracker | ||
{ | ||
public class ExpenseTracker : ExpenseTrackerContainer.ExpenseTrackerBase | ||
{ | ||
public override Empty Initialize(Empty input) | ||
{ | ||
if (State.Initialized.Value) | ||
{ | ||
return new Empty(); | ||
} | ||
State.Initialized.Value = true; | ||
State.Owner.Value = Context.Sender; | ||
State.ExpenseIds.Value = ""; | ||
State.ExpenseCounter.Value = 0; | ||
return new Empty(); | ||
} | ||
|
||
public override StringValue AddExpense(ExpenseInput input) | ||
{ | ||
if (!State.Initialized.Value) | ||
{ | ||
return new StringValue { Value = "Contract not initialized." }; | ||
} | ||
var expenseId = (State.ExpenseCounter.Value + 1).ToString(); | ||
State.ExpenseCounter.Value++; | ||
var timestamp = Context.CurrentBlockTime.Seconds; | ||
State.Expenses[expenseId] = new Expense | ||
{ | ||
ExpenseId = expenseId, | ||
Description = input.Description, | ||
Category = input.Category, | ||
Amount = input.Amount, // Now using int64 for amount | ||
Currency = input.Currency, | ||
CreatedAt = timestamp, | ||
UpdatedAt = timestamp, | ||
Owner = Context.Sender.ToString().Trim('"'), | ||
}; | ||
State.ExpenseExistence[expenseId] = true; | ||
|
||
var existingExpenseIds = State.ExpenseIds.Value; | ||
existingExpenseIds += string.IsNullOrEmpty(existingExpenseIds) ? expenseId : $",{expenseId}"; | ||
State.ExpenseIds.Value = existingExpenseIds; | ||
|
||
return new StringValue { Value = expenseId }; | ||
} | ||
|
||
public override Empty UpdateExpense(ExpenseUpdateInput input) | ||
{ | ||
var expense = State.Expenses[input.ExpenseId]; | ||
if (expense == null) | ||
{ | ||
return new Empty(); // Handle case if expense doesn't exist | ||
} | ||
expense.Description = input.Description ?? expense.Description; | ||
expense.Category = input.Category ?? expense.Category; | ||
expense.Amount = input.Amount != 0 ? input.Amount : expense.Amount; // Now using int64 for amount | ||
expense.Currency = input.Currency ?? expense.Currency; | ||
expense.UpdatedAt = Context.CurrentBlockTime.Seconds; | ||
|
||
State.Expenses[input.ExpenseId] = expense; | ||
return new Empty(); | ||
} | ||
|
||
public override Empty DeleteExpense(StringValue input) | ||
{ | ||
State.Expenses.Remove(input.Value); | ||
State.ExpenseExistence.Remove(input.Value); | ||
|
||
var existingExpenseIds = State.ExpenseIds.Value.Split(','); | ||
var newExpenseIds = new List<string>(existingExpenseIds.Length); | ||
foreach (var expenseId in existingExpenseIds) | ||
{ | ||
if (expenseId != input.Value) | ||
{ | ||
newExpenseIds.Add(expenseId); | ||
} | ||
} | ||
State.ExpenseIds.Value = string.Join(",", newExpenseIds); | ||
|
||
return new Empty(); | ||
} | ||
|
||
public override ExpenseList ListExpenses(StringValue input) | ||
{ | ||
var owner = input.Value; // Get the owner value from the input | ||
var expenseList = new ExpenseList(); | ||
var expenseIds = State.ExpenseIds.Value.Split(','); | ||
foreach (var expenseId in expenseIds) | ||
{ | ||
var expense = State.Expenses[expenseId]; | ||
if (expense != null && expense.Owner == owner) // Filter expenses by owner | ||
{ | ||
expenseList.Expenses.Add(expense); | ||
} | ||
} | ||
return expenseList; | ||
} | ||
|
||
public override Expense GetExpense(StringValue input) | ||
{ | ||
var expense = State.Expenses[input.Value]; | ||
if (expense == null) | ||
{ | ||
return new Expense { ExpenseId = input.Value, Description = "Expense not found." }; | ||
} | ||
return expense; | ||
} | ||
|
||
public override BoolValue GetInitialStatus(Empty input) | ||
{ | ||
return new BoolValue { Value = State.Initialized.Value }; | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
templates/ExpenseTrackerContract/src/ExpenseTracker.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>AElf.Contracts.ExpenseTracker</RootNamespace> | ||
<IsContract>true</IsContract> | ||
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<ObjPath>$(MSBuildProjectDirectory)/$(BaseIntermediateOutputPath)$(Configuration)/$(TargetFramework)/</ObjPath> | ||
</PropertyGroup> | ||
|
||
<Target Name="ProtoGeneratedRecognition" AfterTargets="CoreCompile"> | ||
<ItemGroup> | ||
<Compile Include="$(ObjPath)Protobuf/**/*.cs" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AElf.Sdk.CSharp" Version="1.5.0" /> | ||
<PackageReference Include="AElf.Tools" Version="1.0.2"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
</Project> | ||
|
15 changes: 15 additions & 0 deletions
15
templates/ExpenseTrackerContract/src/ExpenseTrackerState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using AElf.Sdk.CSharp.State; | ||
using AElf.Types; | ||
|
||
namespace AElf.Contracts.ExpenseTracker | ||
{ | ||
public class ExpenseTrackerState : ContractState | ||
{ | ||
public BoolState Initialized { get; set; } | ||
public SingletonState<Address> Owner { get; set; } | ||
public MappedState<string, Expense> Expenses { get; set; } // Mapping of expense ID to Expense | ||
public MappedState<string, bool> ExpenseExistence { get; set; } // Mapping to track expense existence | ||
public StringState ExpenseIds { get; set; } // Concatenated string of expense IDs | ||
public Int32State ExpenseCounter { get; set; } // Counter for generating unique IDs | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
templates/ExpenseTrackerContract/src/Protobuf/contract/expense_tracker.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
syntax = "proto3"; | ||
import "aelf/options.proto"; | ||
import "google/protobuf/empty.proto"; | ||
import "google/protobuf/wrappers.proto"; | ||
import "Protobuf/reference/acs12.proto"; | ||
// The namespace of this class | ||
option csharp_namespace = "AElf.Contracts.ExpenseTracker"; | ||
service ExpenseTracker { | ||
option (aelf.csharp_state) = "AElf.Contracts.ExpenseTracker.ExpenseTrackerState"; | ||
option (aelf.base) = "Protobuf/reference/acs12.proto"; | ||
rpc Initialize (google.protobuf.Empty) returns (google.protobuf.Empty) { | ||
} | ||
rpc AddExpense (ExpenseInput) returns (google.protobuf.StringValue) { | ||
} | ||
rpc UpdateExpense (ExpenseUpdateInput) returns (google.protobuf.Empty) { | ||
} | ||
rpc DeleteExpense (google.protobuf.StringValue) returns (google.protobuf.Empty) { | ||
} | ||
rpc ListExpenses (google.protobuf.StringValue) returns (ExpenseList) { | ||
option (aelf.is_view) = true; | ||
} | ||
rpc GetExpense (google.protobuf.StringValue) returns (Expense) { | ||
option (aelf.is_view) = true; | ||
} | ||
rpc GetInitialStatus (google.protobuf.Empty) returns (google.protobuf.BoolValue) { | ||
option (aelf.is_view) = true; | ||
} | ||
} | ||
|
||
message Expense { | ||
string expense_id = 1; | ||
string description = 2; | ||
string category = 3; | ||
int64 amount = 4; // Store as cents | ||
string currency = 5; | ||
string owner = 6; | ||
int64 created_at = 7; | ||
int64 updated_at = 8; | ||
} | ||
|
||
message ExpenseInput { | ||
string description = 1; | ||
string category = 2; | ||
int64 amount = 3; // Store as cents | ||
string currency = 4; | ||
} | ||
|
||
message ExpenseUpdateInput { | ||
string expense_id = 1; | ||
string description = 2; | ||
string category = 3; | ||
int64 amount = 4; // Store as cents | ||
string currency = 5; | ||
} | ||
|
||
message ExpenseList { | ||
repeated Expense expenses = 1; | ||
} |
10 changes: 10 additions & 0 deletions
10
templates/ExpenseTrackerContract/src/Protobuf/message/authority_info.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
syntax = "proto3"; | ||
|
||
import "aelf/core.proto"; | ||
|
||
option csharp_namespace = "AElf.Contracts.ExpenseTracker"; | ||
|
||
message AuthorityInfo { | ||
aelf.Address contract_address = 1; | ||
aelf.Address owner_address = 2; | ||
} |
35 changes: 35 additions & 0 deletions
35
templates/ExpenseTrackerContract/src/Protobuf/reference/acs12.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* AElf Standards ACS12(User Contract Standard) | ||
* | ||
* Used to manage user contract. | ||
*/ | ||
syntax = "proto3"; | ||
|
||
package acs12; | ||
|
||
import public "aelf/options.proto"; | ||
import public "google/protobuf/empty.proto"; | ||
import public "google/protobuf/wrappers.proto"; | ||
import "aelf/core.proto"; | ||
|
||
option (aelf.identity) = "acs12"; | ||
option csharp_namespace = "AElf.Standards.ACS12"; | ||
|
||
service UserContract{ | ||
|
||
} | ||
|
||
//Specified method fee for user contract. | ||
message UserContractMethodFees { | ||
// List of fees to be charged. | ||
repeated UserContractMethodFee fees = 2; | ||
// Optional based on the implementation of SetConfiguration method. | ||
bool is_size_fee_free = 3; | ||
} | ||
|
||
message UserContractMethodFee { | ||
// The token symbol of the method fee. | ||
string symbol = 1; | ||
// The amount of fees to be charged. | ||
int64 basic_fee = 2; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These should be removed and instead be read from the aelf-sample submodule
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.
Configured to fetch from aelf-samples