Skip to content
This repository has been archived by the owner on Feb 19, 2024. It is now read-only.

Commit

Permalink
A bunch of minor fixes; Added missing actions to client
Browse files Browse the repository at this point in the history
  • Loading branch information
siy committed Jun 18, 2021
1 parent 0debf54 commit 44c818b
Show file tree
Hide file tree
Showing 24 changed files with 544 additions and 165 deletions.
5 changes: 5 additions & 0 deletions radixdlt-core/radixdlt/default.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#
#Fri Jun 18 13:44:36 CEST 2021
cp.port=8080
universe=v2djcmVhdG9yWCIBAsm/OqGKaQ3cgMWH4pVS0MyICRv0ht248s3H7yjgPmLOa2Rlc2NyaXB0aW9udlRoZSBSYWRpeCBkZXYgVW5pdmVyc2VnZ2VuZXNpc4JZA8gBv2FpkEIBAlhZAb9jcnJpWDkGL0pGZ1YycVM4M0pVYXpiWWZSYkpEMWR4b2ZHcktLeHRpRUFtRzk4RHNCendVTEFnOVNvQy9YUkRic3pzcmFkaXgucGFydGljbGVzLnJyaf9CAQFYkwG/YWFYIQX//////////////////////////////////////////2FnWCEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFjcnJpWDkGL0pGZ1YycVM4M0pVYXpiWWZSYkpEMWR4b2ZHcktLeHRpRUFtRzk4RHNCendVTEFnOVNvQy9YUkRic3pjdV90/0IBAVjnAb9hZHNSYWRpeCBOYXRpdmUgVG9rZW5zYWdYIQUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWFpeDRodHRwczovL2Fzc2V0cy5yYWRpeGRsdC5jb20vaWNvbnMvaWNvbi14cmQtMzJ4MzIucG5nYW5kUmFkc2NycmlYOQYvSkZnVjJxUzgzSlVhemJZZlJiSkQxZHhvZkdyS0t4dGlFQW1HOThEc0J6d1VMQWc5U29DL1hSRGJzemVtX3RrbmN1cmx4HGh0dHBzOi8vdG9rZW5zLnJhZGl4ZGx0LmNvbS//QgEAQQFCAQFYvQG/YWFYIQUAAAAAAAAAAAAAAAAAAAAAAAAAAAM7Ljyf0IA86AAAAGFnWCEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFhbfVhb1gnBAICyb86oYppDdyAxYfilVLQzIgJG/SG3bjyzcfvKOA+Ys6FHC6LYXJYOQYvSkZnVjJxUzgzSlVhemJZZlJiSkQxZHhvZkdyS0t4dGlFQW1HOThEc0J6d1VMQWc5U29DL1hSRGJzemF0/0IBBEUBAAAAAUIBAViTAb9hYVghBf///////////////////////////MTRw2Avf8MX////YWdYIQUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWNycmlYOQYvSkZnVjJxUzgzSlVhemJZZlJiSkQxZHhvZkdyS0t4dGlFQW1HOThEc0J6d1VMQWc5U29DL1hSRGJzemN1X3T/QgEAQQFhc79hclghAePQPnf7hdQecg4DUw5M8xQtw7XV/8XTDoLXDlaAM07HYXNYIQEC1yXO+WcbDFLEKDU6VaSlF12hYd89AaG44UkWJzJOg2JzenZjcnlwdG8uZWNkc2Ffc2lnbmF0dXJlYXYB/2JzemRhdG9t/1g9Ab9haYZCAQJRAb9hZQBic3phc2F0AGF2AP9CAQFRAb9hZQFic3phc2F0AGF2AP9CAQBBAWJzemRhdG9t/2VtYWdpYzoxV//9ZG5hbWVsUmFkaXggRGV2bmV0ZHBvcnQZdTBrc2lnbmF0dXJlLnJYIQESw8m8rbKZUZvKDpCULEg61VJDrzEtTutxhlW6U1riAGtzaWduYXR1cmUuc1ghAS2hvdLqQfaUqitEMoEMY5rASE4IjdzR3lNtwnFZms99a3NpZ25hdHVyZS52AGJzem5yYWRpeC51bml2ZXJzZWl0aW1lc3RhbXAbAAWbCMH6QABkdHlwZQL/
ntp.pool=pool.ntp.org
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.stream.Stream;

class CreateMutableTokenAction implements TransactionAction {
private final REAddr from;
private final ECPublicKey signer;
private final String name;
private final String symbol;
Expand All @@ -33,8 +34,9 @@ class CreateMutableTokenAction implements TransactionAction {
private final String description;

CreateMutableTokenAction(
ECPublicKey signer, String name, String symbol, String iconUrl, String tokenUrl, String description
REAddr from, ECPublicKey signer, String name, String symbol, String iconUrl, String tokenUrl, String description
) {
this.from = from;
this.signer = signer;
this.name = name;
this.symbol = symbol;
Expand All @@ -45,7 +47,7 @@ class CreateMutableTokenAction implements TransactionAction {

@Override
public REAddr getFrom() {
return null;
return from;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class RegisterValidatorAction implements TransactionAction {

@Override
public REAddr getFrom() {
return null;
return REAddr.ofPubKeyAccount(delegate);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,19 @@ static TransactionAction update(ECPublicKey delegate, Optional<String> name, Opt
}

static TransactionAction createFixed(
REAddr from, REAddr rri, String symbol, String name,
REAddr from, ECPublicKey signer, String symbol, String name,
String description, String iconUrl, String tokenUrl, UInt256 amount
) {
return new CreateFixedTokenAction(from, amount, rri, name, symbol, iconUrl, tokenUrl, description);
return new CreateFixedTokenAction(from, amount, REAddr.ofPubKeyAccount(signer), name,
symbol, iconUrl, tokenUrl, description);
}

static TransactionAction createMutable(
ECPublicKey signer, String symbol, String name,
REAddr from, ECPublicKey signer, String symbol, String name,
Optional<String> description, Optional<String> iconUrl, Optional<String> tokenUrl
) {
return new CreateMutableTokenAction(
signer, name, symbol,
from, signer, name, symbol,
iconUrl.orElse(null), tokenUrl.orElse(null), description.orElse(null)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private Result<TransactionAction> parseByType(ActionType type, JSONObject elemen
case CREATE_FIXED:
return allOf(
from(element),
rri(element),
pubKey(element),
symbol(element),
name(element),
description(element),
Expand All @@ -149,6 +149,7 @@ private Result<TransactionAction> parseByType(ActionType type, JSONObject elemen

case CREATE_MUTABLE:
return allOf(
from(element),
pubKey(element),
symbol(element),
name(element),
Expand All @@ -160,7 +161,7 @@ private Result<TransactionAction> parseByType(ActionType type, JSONObject elemen
}

private Result<ECPublicKey> pubKey(JSONObject element) {
return param(element, "signerPublicKey")
return param(element, "publicKeyOfSigner")
.flatMap(ECPublicKey::fromHexString);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ static JSONObject prepareApiConfiguration(List<EndpointStatus> statuses) {

return jsonObject().put(
"endpoints",
fromList(statuses, endpoint -> "/" + endpoint)
fromList(enabled, endpoint -> "/" + endpoint)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,11 @@ public void unregisterValidatorIsParsedCorrectly() {
@Test
public void createFixedTokenIsParsedCorrectly() {
var fromAddr = AccountAddress.of(from);
var signer = ECKeyPair.generateNew().getPublicKey();

var source = "[{\"type\":\"CreateFixedSupplyToken\", \"from\":\"%s\", \"rri\":\"%s\", \"symbol\":\"%s\", "
var source = "[{\"type\":\"CreateFixedSupplyToken\", \"from\":\"%s\", \"publicKeyOfSigner\":\"%s\", \"symbol\":\"%s\", "
+ "\"name\":\"%s\", \"description\":\"%s\", \"iconUrl\":\"%s\", \"tokenUrl\":\"%s\", \"supply\":\"%s\"}]";
var actions = jsonArray(String.format(source, fromAddr, rri, "symbol",
var actions = jsonArray(String.format(source, fromAddr, signer.toHex(), "symbol",
"name", "description", "http://icon.url/", "http://token.url/", UInt256.TEN
));

Expand All @@ -455,7 +456,7 @@ public void createFixedTokenIsParsedCorrectly() {
.ifPresentOrElse(
create -> {
assertEquals(from, create.getAccountAddr());
assertEquals(rri, create.getResourceAddr());
assertEquals(REAddr.ofPubKeyAccount(signer), create.getResourceAddr());
assertEquals("symbol", create.getSymbol());
assertEquals("name", create.getName());
assertEquals("description", create.getDescription());
Expand All @@ -471,9 +472,10 @@ public void createFixedTokenIsParsedCorrectly() {
@Test
public void createMutableTokenIsParsedCorrectlyWithOptionalElements() {
var publicKey = ECKeyPair.generateNew().getPublicKey();
var source = "[{\"type\":\"CreateMutableSupplyToken\", \"symbol\":\"%s\", \"name\":\"%s\", "
+ "\"description\":\"%s\", \"iconUrl\":\"%s\", \"tokenUrl\":\"%s\", \"signerPublicKey\":\"%s\"}]";
var actions = jsonArray(String.format(source, "symbol", "name",
var fromAddr = AccountAddress.of(from);
var source = "[{\"type\":\"CreateMutableSupplyToken\", \"from\":\"%s\", \"symbol\":\"%s\", \"name\":\"%s\", "
+ "\"description\":\"%s\", \"iconUrl\":\"%s\", \"tokenUrl\":\"%s\", \"publicKeyOfSigner\":\"%s\"}]";
var actions = jsonArray(String.format(source, fromAddr, "symbol", "name",
"description", "http://icon.url/", "http://token.url/", publicKey.toHex()
));

Expand Down Expand Up @@ -501,8 +503,9 @@ public void createMutableTokenIsParsedCorrectlyWithOptionalElements() {
@Test
public void createMutableTokenIsParsedCorrectlyWithoutOptionalElements() {
var publicKey = ECKeyPair.generateNew().getPublicKey();
var source = "[{\"type\":\"CreateMutableSupplyToken\", \"symbol\":\"%s\", \"name\":\"%s\", \"signerPublicKey\":\"%s\"}]";
var actions = jsonArray(String.format(source, "symbol", "name", publicKey.toHex()));
var fromAddr = AccountAddress.of(from);
var source = "[{\"type\":\"CreateMutableSupplyToken\", \"from\":\"%s\", \"symbol\":\"%s\", \"name\":\"%s\", \"publicKeyOfSigner\":\"%s\"}]";
var actions = jsonArray(String.format(source, fromAddr, "symbol", "name", publicKey.toHex()));

actionParserService.parse(actions)
.onFailure(this::fail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public enum ActionType {
MINT("MintTokens"),
REGISTER_VALIDATOR("RegisterValidator"),
UNREGISTER_VALIDATOR("UnregisterValidator"),
UPDATE_VALIDATOR("UpdateValidator"),
CREATE_FIXED("CreateFixedSupplyToken"),
CREATE_MUTABLE("CreateMutableSupplyToken"),
UNKNOWN("Other");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,24 @@
package com.radixdlt.client.lib.api;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.radixdlt.client.lib.dto.Action;
//import com.radixdlt.client.lib.dto.Action;
import com.radixdlt.client.lib.api.action.Action;
import com.radixdlt.client.lib.api.action.BurnAction;
import com.radixdlt.client.lib.api.action.CreateFixedTokenAction;
import com.radixdlt.client.lib.api.action.CreateMutableTokenAction;
import com.radixdlt.client.lib.api.action.MintAction;
import com.radixdlt.client.lib.api.action.RegisterValidatorAction;
import com.radixdlt.client.lib.api.action.StakeAction;
import com.radixdlt.client.lib.api.action.TransferAction;
import com.radixdlt.client.lib.api.action.UnregisterValidatorAction;
import com.radixdlt.client.lib.api.action.UnstakeAction;
import com.radixdlt.client.lib.api.action.UpdateValidatorAction;
import com.radixdlt.crypto.ECPublicKey;
import com.radixdlt.utils.UInt256;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class TransactionRequest {
private final List<Action> actions;
Expand Down Expand Up @@ -53,19 +66,62 @@ public static final class TransactionRequestBuilder {

private TransactionRequestBuilder() { }

//TODO: add more actions
public TransactionRequestBuilder transfer(AccountAddress from, AccountAddress to, UInt256 amount, String rri) {
actions.add(Action.transfer(from, to, amount, rri));
actions.add(new TransferAction(from, to, amount, rri));
return this;
}

public TransactionRequestBuilder stake(AccountAddress from, ValidatorAddress validator, UInt256 amount) {
actions.add(Action.stake(from, validator, amount));
actions.add(new StakeAction(from, validator, amount));
return this;
}

public TransactionRequestBuilder unstake(AccountAddress from, ValidatorAddress validator, UInt256 amount) {
actions.add(Action.unstake(from, validator, amount));
actions.add(new UnstakeAction(from, validator, amount));
return this;
}

public TransactionRequestBuilder burn(AccountAddress from, UInt256 amount, String rri) {
actions.add(new BurnAction(from, amount, rri));
return this;
}

public TransactionRequestBuilder mint(AccountAddress from, UInt256 amount, String rri) {
actions.add(new MintAction(from, amount, rri));
return this;
}

public TransactionRequestBuilder registerValidator(ValidatorAddress delegate, Optional<String> name, Optional<String> url) {
actions.add(new RegisterValidatorAction(delegate, name.orElse(null), url.orElse(null)));
return this;
}

public TransactionRequestBuilder unregisterValidator(ValidatorAddress delegate, Optional<String> name, Optional<String> url) {
actions.add(new UnregisterValidatorAction(delegate, name.orElse(null), url.orElse(null)));
return this;
}

public TransactionRequestBuilder updateValidator(ValidatorAddress delegate, Optional<String> name, Optional<String> url) {
actions.add(new UpdateValidatorAction(delegate, name.orElse(null), url.orElse(null)));
return this;
}

public TransactionRequestBuilder createFixed(
AccountAddress from, ECPublicKey signer, String rri, String symbol, String name,
String description, String iconUrl, String tokenUrl, UInt256 amount
) {
actions.add(new CreateFixedTokenAction(from, signer, amount, rri, name, symbol, iconUrl, tokenUrl, description));
return this;
}

public TransactionRequestBuilder createMutable(
AccountAddress from, ECPublicKey signer, String symbol, String name,
Optional<String> description, Optional<String> iconUrl, Optional<String> tokenUrl
) {
new CreateMutableTokenAction(
from, signer, name, symbol,
iconUrl.orElse(null), tokenUrl.orElse(null), description.orElse(null)
);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* (C) Copyright 2021 Radix DLT Ltd
*
* Radix DLT Ltd licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the
* License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/

package com.radixdlt.client.lib.api.action;

public interface Action {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* (C) Copyright 2021 Radix DLT Ltd
*
* Radix DLT Ltd licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the
* License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/

package com.radixdlt.client.lib.api.action;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.radixdlt.client.lib.api.AccountAddress;
import com.radixdlt.client.lib.api.ActionType;
import com.radixdlt.utils.UInt256;

@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
public class BurnAction implements Action {
private final ActionType type = ActionType.BURN;
private final AccountAddress from;
private final UInt256 amount;
private final String rri;

public BurnAction(AccountAddress from, UInt256 amount, String rri) {
this.from = from;
this.amount = amount;
this.rri = rri;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* (C) Copyright 2021 Radix DLT Ltd
*
* Radix DLT Ltd licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the
* License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/

package com.radixdlt.client.lib.api.action;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.radixdlt.client.lib.api.AccountAddress;
import com.radixdlt.client.lib.api.ActionType;
import com.radixdlt.crypto.ECPublicKey;
import com.radixdlt.utils.UInt256;

@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
public class CreateFixedTokenAction implements Action {
private final ActionType type = ActionType.CREATE_FIXED;
private final AccountAddress from;
private final ECPublicKey signer;
private final UInt256 amount;
private final String rri;
private final String name;
private final String symbol;
private final String iconUrl;
private final String tokenUrl;
private final String description;

public CreateFixedTokenAction(
AccountAddress from,
ECPublicKey signer, UInt256 amount,
String rri,
String name,
String symbol,
String iconUrl,
String tokenUrl,
String description
) {
this.from = from;
this.signer = signer;
this.amount = amount;
this.rri = rri;
this.name = name;
this.symbol = symbol;
this.iconUrl = iconUrl;
this.tokenUrl = tokenUrl;
this.description = description;
}
}
Loading

0 comments on commit 44c818b

Please sign in to comment.