Skip to content

Commit 0df03db

Browse files
authored
fix: Updated with inter-contract calls logic (#321)
1 parent 4039950 commit 0df03db

File tree

1 file changed

+64
-0
lines changed
  • docs/quick-start/developers/allowance-dapp

1 file changed

+64
-0
lines changed

docs/quick-start/developers/allowance-dapp/index.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,70 @@ namespace AElf.Contracts.AllowanceContract
441441
}
442442
```
443443

444+
### Add Inter-Contract Calls
445+
- Now, AllowanceContract needs to create a reference with the RoleContract. First, AllowanceContract will use the `role_contract.proto` file inside the **Protobuf/reference** folder. Copy the `role_contract.proto` from the role-contract/src/Protobuf/contract folder.
446+
447+
```csharp title="role_contract.proto"
448+
syntax = "proto3";
449+
450+
import "aelf/core.proto";
451+
452+
import "google/protobuf/empty.proto";
453+
import "Protobuf/reference/acs12.proto";
454+
import "aelf/options.proto";
455+
import "google/protobuf/wrappers.proto";
456+
457+
// The namespace of this class
458+
option csharp_namespace = "AElf.Contracts.RoleContract";
459+
460+
service RoleContract {
461+
462+
// The name of the state class the smart contract is going to use to access blockchain state
463+
option (aelf.csharp_state) = "AElf.Contracts.RoleContract.RoleContractState";
464+
option (aelf.base) = "Protobuf/reference/acs12.proto";
465+
466+
rpc Initialize (google.protobuf.Empty) returns (google.protobuf.Empty){
467+
468+
}
469+
470+
rpc SetAdmin (aelf.Address) returns (google.protobuf.Empty) {
471+
}
472+
473+
rpc GetAdmin (google.protobuf.Empty) returns (google.protobuf.StringValue) {
474+
option (aelf.is_view) = true;
475+
}
476+
477+
rpc SetParent (aelf.Address) returns (google.protobuf.Empty) {
478+
}
479+
480+
rpc GetParent (google.protobuf.Empty) returns (google.protobuf.StringValue) {
481+
option (aelf.is_view) = true;
482+
}
483+
484+
rpc SetChild (aelf.Address) returns (google.protobuf.Empty) {
485+
}
486+
487+
rpc GetChild (google.protobuf.Empty) returns (google.protobuf.StringValue) {
488+
option (aelf.is_view) = true;
489+
}
490+
491+
}
492+
```
493+
494+
- Now, create a file inside `src` folder and name it as `ContractReferences.cs` and add the following code to establish connection between AllowanceContract and the RoleContract.
495+
496+
```csharp title="ContractReferences.cs"
497+
using AElf.Contracts.RoleContract;
498+
499+
namespace AElf.Contracts.AllowanceContract
500+
{
501+
public partial class AllowanceContractState
502+
{
503+
internal RoleContractContainer.RoleContractReferenceState RoleContract { get; set; }
504+
}
505+
}
506+
```
507+
444508
### Building Allowance Smart Contract
445509

446510
- Build the smart contract code with the following command inside `src` folder:

0 commit comments

Comments
 (0)