-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from AElfProject/feat/simple-dao-template
Feature - Simple DAO Smart Contract Template
- Loading branch information
Showing
18 changed files
with
3,294 additions
and
1 deletion.
There are no files selected for viewing
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
21 changes: 21 additions & 0 deletions
21
templates/SimpleDAOContract/.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", | ||
"author": "AElf", | ||
"classifications": [ | ||
"AElf/SmartContract" | ||
], | ||
"identity": "AElf.Contract.SimpleDAO.Template", | ||
"name": "AElf Contract SimpleDAO Template", | ||
"shortName": "aelf-simple-dao", | ||
"tags": { | ||
"language": "C#", | ||
"type": "project" | ||
}, | ||
"sourceName": "SimpleDAO", | ||
"symbols": { | ||
"NamespacePath": { | ||
"type": "parameter", | ||
"replaces": "AElf.Contracts.SimpleDAO" | ||
} | ||
} | ||
} |
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,12 @@ | ||
using AElf.Sdk.CSharp.State; | ||
using AElf.Contracts.MultiToken; | ||
using AElf.Types; | ||
|
||
namespace AElf.Contracts.SimpleDAO | ||
{ | ||
// The state class is access the blockchain state | ||
public partial class SimpleDAOState | ||
{ | ||
internal TokenContractContainer.TokenContractReferenceState TokenContract { get; set; } | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
templates/SimpleDAOContract/src/Protobuf/contract/simple_dao.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,110 @@ | ||
syntax = "proto3"; | ||
|
||
import "aelf/core.proto"; | ||
import "aelf/options.proto"; | ||
import "google/protobuf/empty.proto"; | ||
import "Protobuf/reference/acs12.proto"; | ||
import public "google/protobuf/timestamp.proto"; | ||
|
||
// The namespace of this class | ||
option csharp_namespace = "AElf.Contracts.SimpleDAO"; | ||
|
||
service SimpleDAO { | ||
// The name of the state class the smart contract is going to use to access | ||
// blockchain state | ||
option (aelf.csharp_state) = "AElf.Contracts.SimpleDAO.SimpleDAOState"; | ||
option (aelf.base) = "Protobuf/reference/acs12.proto"; | ||
|
||
// Actions -> Methods that change state of smart contract | ||
// This method sets up the initial state of our StackUpDAO smart contract | ||
rpc Initialize(InitializeInput) returns (google.protobuf.Empty); | ||
|
||
// This method allows a user to create a proposal for other users to vote on. | ||
// The method takes in a "CreateProposalInput" message which comprises of an | ||
// address, a title, description and a vote threshold (i.e how many votes | ||
// required for the proposal to pass) | ||
rpc CreateProposal(CreateProposalInput) returns (google.protobuf.Empty); | ||
|
||
// This method allows a user to vote on proposals towards a specific proposal. | ||
// This method takes in a "VoteInput" message which takes in the address of | ||
// the voter, specific proposal and a boolean which represents their vote | ||
rpc Vote(VoteInput) returns (google.protobuf.Empty); | ||
|
||
rpc Withdraw(WithdrawInput) returns (google.protobuf.Empty); | ||
|
||
// Views -> Methods that does not change state of smart contract | ||
// This method allows a user to fetch a list of proposals that had been | ||
// created by members of the DAO | ||
rpc GetAllProposals(google.protobuf.Empty) returns (ProposalList) { | ||
option (aelf.is_view) = true; | ||
} | ||
|
||
// aelf requires explicit getter methods to access the state value, | ||
// so we provide these three getter methods for accessing the state | ||
// This method allows a user to fetch a proposal by proposalId | ||
rpc GetProposal (google.protobuf.StringValue) returns (Proposal) { | ||
option (aelf.is_view) = true; | ||
} | ||
|
||
// get the token symbol for this DAO | ||
rpc GetTokenSymbol (google.protobuf.Empty) returns (google.protobuf.StringValue) { | ||
option (aelf.is_view) = true; | ||
} | ||
|
||
rpc HasVoted (HasVotedInput) returns (google.protobuf.BoolValue) { | ||
option (aelf.is_view) = true; | ||
} | ||
} | ||
|
||
message Proposal { | ||
string id = 1; | ||
string title = 2; | ||
string description = 3; | ||
string status = 4; // e.g., "IN PROGRESS", "PASSED", "DENIED" | ||
aelf.Address proposer = 5; | ||
google.protobuf.Timestamp start_timestamp = 6; | ||
google.protobuf.Timestamp end_timestamp = 7; | ||
ProposalResult result = 8; | ||
} | ||
|
||
message ProposalResult { | ||
int64 approve_counts = 1; | ||
int64 reject_counts = 2; | ||
int64 abstain_counts = 3; | ||
} | ||
|
||
message CreateProposalInput { | ||
string title = 1; | ||
string description = 2; | ||
google.protobuf.Timestamp start_timestamp = 3; | ||
google.protobuf.Timestamp end_timestamp = 4; | ||
} | ||
|
||
enum VoteOption { | ||
APPROVED = 0; | ||
REJECTED = 1; | ||
ABSTAINED = 2; | ||
} | ||
|
||
message VoteInput { | ||
string proposalId = 1; | ||
VoteOption vote = 2; | ||
int64 amount = 3; | ||
} | ||
|
||
message InitializeInput { | ||
string tokenSymbol = 1; | ||
} | ||
|
||
message WithdrawInput { | ||
string proposalId = 1; | ||
} | ||
|
||
message ProposalList { | ||
repeated Proposal proposals = 1; | ||
} | ||
|
||
message HasVotedInput { | ||
string proposalId = 1; | ||
aelf.Address address = 2; | ||
} |
10 changes: 10 additions & 0 deletions
10
templates/SimpleDAOContract/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.SimpleDAO"; | ||
|
||
message AuthorityInfo { | ||
aelf.Address contract_address = 1; | ||
aelf.Address owner_address = 2; | ||
} |
35 changes: 35 additions & 0 deletions
35
templates/SimpleDAOContract/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.