Skip to content
Merged
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
7 changes: 4 additions & 3 deletions .github/workflows/sonarqube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ jobs:
- name: Create temporary global.json
run: echo '{"sdk":{"version":"8.0.*"}}' > ./global.json
- name: Set up JDK 17
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
- name: Cache SonarQube packages
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarQube scanner
id: cache-sonar-scanner
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ./.sonar/scanner
key: ${{ runner.os }}-sonar-scanner
Expand Down
1 change: 1 addition & 0 deletions contract/AElf.Contracts.MultiToken/TokenContractState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public partial class TokenContractState : ContractState
public SingletonState<DeveloperFeeController> DeveloperFeeController { get; set; }
public SingletonState<AuthorityInfo> SymbolToPayTxFeeController { get; set; }
public SingletonState<AuthorityInfo> SideChainRentalController { get; set; }
public SingletonState<AuthorityInfo> TransferBlackListController { get; set; }

/// <summary>
/// symbol -> address -> is in white list.
Expand Down
48 changes: 47 additions & 1 deletion contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -853,17 +853,63 @@

public override Empty AddToTransferBlackList(Address input)
{
AssertSenderAddressWith(GetDefaultParliamentController().OwnerAddress);
AssertControllerForTransferBlackList();

Check warning on line 856 in contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs#L856

Added line #L856 was not covered by tests
Assert(input != null && !input.Value.IsNullOrEmpty(), "Invalid address.");
State.TransferBlackList[input] = true;
return new Empty();
}

public override Empty BatchAddToTransferBlackList(BatchAddToTransferBlackListInput input)
{
AssertControllerForTransferBlackList();

Check warning on line 864 in contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs#L863-L864

Added lines #L863 - L864 were not covered by tests
Assert(input != null && input.Addresses != null && input.Addresses.Count > 0, "Invalid input.");

// Validate all addresses first
foreach (var address in input.Addresses)
{

Check warning on line 869 in contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs#L869

Added line #L869 was not covered by tests
Assert(address != null && !address.Value.IsNullOrEmpty(), "Invalid address.");
}

Check warning on line 871 in contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs#L871

Added line #L871 was not covered by tests

// Remove duplicates and add to blacklist
var uniqueAddresses = input.Addresses.Distinct().ToList();

Check warning on line 874 in contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs#L874

Added line #L874 was not covered by tests
foreach (var address in uniqueAddresses)
{
State.TransferBlackList[address] = true;
}

Check warning on line 878 in contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs#L876-L878

Added lines #L876 - L878 were not covered by tests

return new Empty();
}

Check warning on line 881 in contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs#L880-L881

Added lines #L880 - L881 were not covered by tests

public override Empty RemoveFromTransferBlackList(Address input)
{
// Removing from transfer blacklist requires higher security and response speed is not critical,
// so it should be controlled by Parliament.
AssertSenderAddressWith(GetDefaultParliamentController().OwnerAddress);
Assert(input != null && !input.Value.IsNullOrEmpty(), "Invalid address.");
State.TransferBlackList[input] = false;
return new Empty();
}

public override Empty BatchRemoveFromTransferBlackList(BatchRemoveFromTransferBlackListInput input)
{

Check warning on line 894 in contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs#L894

Added line #L894 was not covered by tests
// Removing from transfer blacklist requires higher security and response speed is not critical,
// so it should be controlled by Parliament.
AssertSenderAddressWith(GetDefaultParliamentController().OwnerAddress);

Check warning on line 897 in contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs#L897

Added line #L897 was not covered by tests
Assert(input != null && input.Addresses != null && input.Addresses.Count > 0, "Invalid input.");

// Validate all addresses first
foreach (var address in input.Addresses)
{

Check warning on line 902 in contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs#L902

Added line #L902 was not covered by tests
Assert(address != null && !address.Value.IsNullOrEmpty(), "Invalid address.");
}

Check warning on line 904 in contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs#L904

Added line #L904 was not covered by tests

// Remove duplicates and remove from blacklist
var uniqueAddresses = input.Addresses.Distinct().ToList();

Check warning on line 907 in contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs#L907

Added line #L907 was not covered by tests
foreach (var address in uniqueAddresses)
{
State.TransferBlackList[address] = false;
}

Check warning on line 911 in contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs#L909-L911

Added lines #L909 - L911 were not covered by tests

return new Empty();
}

Check warning on line 914 in contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs#L913-L914

Added lines #L913 - L914 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@
return new Empty();
}

public override Empty ChangeTransferBlackListController(AuthorityInfo input)
{
AssertSenderAddressWith(GetDefaultParliamentController().OwnerAddress);
var organizationExist = CheckOrganizationExist(input);
Assert(organizationExist, "Invalid authority input.");
State.TransferBlackListController.Value = input;
return new Empty();
}

Check warning on line 97 in contract/AElf.Contracts.MultiToken/TokenContract_Method_Authorization.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Method_Authorization.cs#L91-L97

Added lines #L91 - L97 were not covered by tests

private void CreateReferendumControllerForUserFee(Address parliamentAddress)
{
State.ReferendumContract.CreateOrganizationBySystemContract.Send(
Expand Down Expand Up @@ -364,6 +373,13 @@
};
}

private AuthorityInfo GetTransferBlackListController()
{

Check warning on line 377 in contract/AElf.Contracts.MultiToken/TokenContract_Method_Authorization.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Method_Authorization.cs#L377

Added line #L377 was not covered by tests
if (State.TransferBlackListController.Value == null)
return GetDefaultParliamentController();
return State.TransferBlackListController.Value;
}

Check warning on line 381 in contract/AElf.Contracts.MultiToken/TokenContract_Method_Authorization.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Method_Authorization.cs#L379-L381

Added lines #L379 - L381 were not covered by tests

private void AssertDeveloperFeeController()
{
Assert(State.DeveloperFeeController.Value != null,
Expand Down Expand Up @@ -396,5 +412,11 @@
Assert(State.SideChainRentalController.Value.OwnerAddress == Context.Sender, "no permission");
}

private void AssertControllerForTransferBlackList()
{
var controller = GetTransferBlackListController();
Assert(Context.Sender == controller.OwnerAddress, "No permission");
}

Check warning on line 419 in contract/AElf.Contracts.MultiToken/TokenContract_Method_Authorization.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Method_Authorization.cs#L416-L419

Added lines #L416 - L419 were not covered by tests

#endregion
}
6 changes: 6 additions & 0 deletions contract/AElf.Contracts.MultiToken/TokenContract_Views.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,10 @@
{
return new BoolValue { Value = State.TransferBlackList[input] };
}

[View]
public override AuthorityInfo GetTransferBlackListController(Empty input)
{
return GetTransferBlackListController();
}

Check warning on line 306 in contract/AElf.Contracts.MultiToken/TokenContract_Views.cs

View check run for this annotation

Codecov / codecov/patch

contract/AElf.Contracts.MultiToken/TokenContract_Views.cs#L304-L306

Added lines #L304 - L306 were not covered by tests
}
29 changes: 28 additions & 1 deletion protobuf/token_contract_impl.proto
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ service TokenContractImpl {
rpc ChangeDeveloperController (AuthorityInfo) returns (google.protobuf.Empty) {
}

// Change the governance organization of the transfer blacklist management.
rpc ChangeTransferBlackListController (AuthorityInfo) returns (google.protobuf.Empty) {
}

rpc ConfigTransactionFeeFreeAllowances (ConfigTransactionFeeFreeAllowancesInput) returns (google.protobuf.Empty) {
}

Expand Down Expand Up @@ -136,6 +140,11 @@ service TokenContractImpl {
option (aelf.is_view) = true;
}

// Query the governance organization of the transfer blacklist management.
rpc GetTransferBlackListController (google.protobuf.Empty) returns (AuthorityInfo) {
option (aelf.is_view) = true;
}

// Compute the virtual address for locking.
rpc GetVirtualAddressForLocking (GetVirtualAddressForLockingInput) returns (aelf.Address) {
option (aelf.is_view) = true;
Expand Down Expand Up @@ -186,12 +195,22 @@ service TokenContractImpl {
rpc ExtendSeedExpirationTime (ExtendSeedExpirationTimeInput) returns (google.protobuf.Empty) {
}

// Add an address to the transfer blacklist. Only parliament owner can call this method.
// Add an address to the transfer blacklist.
rpc AddToTransferBlackList (aelf.Address) returns (google.protobuf.Empty) {
}

// Add multiple addresses to the transfer blacklist.
rpc BatchAddToTransferBlackList (BatchAddToTransferBlackListInput) returns (google.protobuf.Empty) {
}

// Remove an address from the transfer blacklist. Only parliament owner can call this method.
rpc RemoveFromTransferBlackList (aelf.Address) returns (google.protobuf.Empty) {
}

// Remove multiple addresses from the transfer blacklist. Only parliament owner can call this method.
rpc BatchRemoveFromTransferBlackList (BatchRemoveFromTransferBlackListInput) returns (google.protobuf.Empty) {
}

// Check if an address is in the transfer blacklist.
rpc IsInTransferBlackList (aelf.Address) returns (google.protobuf.BoolValue) {
option (aelf.is_view) = true;
Expand Down Expand Up @@ -471,4 +490,12 @@ message SeedExpirationTimeUpdated {
string symbol = 2;
int64 old_expiration_time = 3;
int64 new_expiration_time = 4;
}

message BatchAddToTransferBlackListInput {
repeated aelf.Address addresses = 1;
}

message BatchRemoveFromTransferBlackListInput {
repeated aelf.Address addresses = 1;
}
Loading
Loading