-
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.
Account Transaction : Configure Baker and Delegation (#150)
Co-authored-by: parv <[email protected]> Co-authored-by: Parv Sharma <[email protected]>
- Loading branch information
1 parent
f743e59
commit 85f2089
Showing
37 changed files
with
1,732 additions
and
189 deletions.
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
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
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
40 changes: 40 additions & 0 deletions
40
concordium-sdk/src/main/java/com/concordium/sdk/crypto/bakertransactions/BakerKeys.java
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,40 @@ | ||
package com.concordium.sdk.crypto.bakertransactions; | ||
|
||
import com.concordium.sdk.crypto.CryptoJniNative; | ||
import com.concordium.sdk.crypto.CryptoJniResultCode; | ||
import com.concordium.sdk.crypto.NativeResolver; | ||
import com.concordium.sdk.exceptions.CryptoJniException; | ||
import com.concordium.sdk.serializing.JsonMapper; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import lombok.val; | ||
|
||
public final class BakerKeys { | ||
//static block to load native library | ||
static { | ||
NativeResolver.loadLib(); | ||
} | ||
|
||
//Method to create baker keys | ||
public static BakerKeysJniOutput createBakerKeys() { | ||
|
||
BakerKeysResult result = null; | ||
try { | ||
//Invoking native method to generate baker keys | ||
val jsonStr = CryptoJniNative.generateBakerKeys(); | ||
result = JsonMapper.INSTANCE.readValue(jsonStr, BakerKeysResult.class); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
if (!result.isok()) { | ||
throw CryptoJniException.from( | ||
result.getErr().orElse(CryptoJniResultCode.ERROR_UNKNOWN_RESULT_CODE)); | ||
} | ||
|
||
return result.getOk().orElseThrow( | ||
() -> CryptoJniException.from(CryptoJniResultCode.ERROR_UNKNOWN_RESULT_CODE)); | ||
|
||
} | ||
|
||
} | ||
|
||
|
35 changes: 35 additions & 0 deletions
35
...ium-sdk/src/main/java/com/concordium/sdk/crypto/bakertransactions/BakerKeysJniOutput.java
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 @@ | ||
package com.concordium.sdk.crypto.bakertransactions; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.extern.jackson.Jacksonized; | ||
|
||
@Jacksonized | ||
@Builder | ||
@Data | ||
public class BakerKeysJniOutput { | ||
/** | ||
* New public key for participating in the election lottery. | ||
*/ | ||
private final String electionVerifyKey; | ||
/** | ||
* New public key for verifying this baker's signatures. | ||
*/ | ||
private final String signatureVerifyKey; | ||
/** | ||
* New public key for verifying this baker's signature on finalization records. | ||
*/ | ||
private final String aggregationVerifyKey; | ||
/** | ||
* A secret key used by a baker to sign blocks. | ||
*/ | ||
private final String signatureSignKey; | ||
/** | ||
* A private key for participating in the election lottery. | ||
*/ | ||
private final String electionPrivateKey; | ||
/** | ||
* A secret key used by bakers and finalizers to sign finalization records. | ||
*/ | ||
private final String aggregationSignKey; | ||
} |
44 changes: 44 additions & 0 deletions
44
...ordium-sdk/src/main/java/com/concordium/sdk/crypto/bakertransactions/BakerKeysResult.java
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,44 @@ | ||
package com.concordium.sdk.crypto.bakertransactions; | ||
|
||
import com.concordium.sdk.crypto.CryptoJniResultCode; | ||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Data; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Class that holds the result of generating baker keys payload | ||
*/ | ||
@Data | ||
public class BakerKeysResult { | ||
/** | ||
* An optional `BakerKeysJniOutput` object, containing the output of the generate baker keys function. | ||
*/ | ||
@JsonProperty("Ok") | ||
private final Optional<BakerKeysJniOutput> ok; | ||
|
||
/** | ||
* An optional `CryptoJniResultCode` object, containing an error code if the generate baker keys function failed. | ||
*/ | ||
@JsonProperty("Err") | ||
private final Optional<CryptoJniResultCode> err; | ||
|
||
@JsonCreator | ||
BakerKeysResult( | ||
@JsonProperty("Ok") BakerKeysJniOutput ok, | ||
@JsonProperty("Err") CryptoJniResultCode err | ||
) { | ||
this.ok = Optional.ofNullable(ok); | ||
this.err = Optional.ofNullable(err); | ||
} | ||
|
||
/** | ||
* Returns a boolean indicating whether the `ok` field is present (i.e. whether the baker key was successfully generated). | ||
* | ||
* @return a boolean indicating whether the `ok` field is present. | ||
*/ | ||
public boolean isok() { | ||
return ok.isPresent(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...ium-sdk/src/main/java/com/concordium/sdk/crypto/bakertransactions/ConfigureBakerKeys.java
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,43 @@ | ||
package com.concordium.sdk.crypto.bakertransactions; | ||
|
||
import com.concordium.sdk.crypto.CryptoJniNative; | ||
import com.concordium.sdk.crypto.CryptoJniResultCode; | ||
import com.concordium.sdk.crypto.NativeResolver; | ||
import com.concordium.sdk.exceptions.CryptoJniException; | ||
import com.concordium.sdk.serializing.JsonMapper; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import lombok.val; | ||
|
||
public final class ConfigureBakerKeys { | ||
//static block to load native library | ||
static { | ||
NativeResolver.loadLib(); | ||
} | ||
|
||
// Method to generate the payload for configuring baker keys | ||
public static ConfigureBakerKeysJniOutput generateConfigureBakerKeysPayload(ConfigureBakerKeysJniInput jniInput) { | ||
|
||
ConfigureBakerKeysResult result = null; | ||
try { | ||
val inputJsonString = JsonMapper.INSTANCE.writeValueAsString(jniInput); | ||
//Invoking native method to generate configure baker keys payload | ||
val jsonStr = CryptoJniNative.generateConfigureBakerKeysPayload(inputJsonString); | ||
result = JsonMapper.INSTANCE.readValue(jsonStr, ConfigureBakerKeysResult.class); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
if (!result.isok()) { | ||
throw CryptoJniException.from( | ||
result.getErr().orElse(CryptoJniResultCode.ERROR_UNKNOWN_RESULT_CODE)); | ||
} | ||
|
||
// return the ok field of the result object | ||
return result.getOk().orElseThrow( | ||
() -> CryptoJniException.from(CryptoJniResultCode.ERROR_UNKNOWN_RESULT_CODE)); | ||
|
||
} | ||
|
||
} | ||
|
||
|
21 changes: 21 additions & 0 deletions
21
...src/main/java/com/concordium/sdk/crypto/bakertransactions/ConfigureBakerKeysJniInput.java
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 @@ | ||
package com.concordium.sdk.crypto.bakertransactions; | ||
|
||
import com.concordium.sdk.transactions.AccountAddress; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
/** | ||
* Configure the account as a baker. Only valid for protocol version 4 and up. | ||
*/ | ||
@Data | ||
@Builder | ||
public class ConfigureBakerKeysJniInput { | ||
/** | ||
* The address of the account that will be configured as a baker | ||
*/ | ||
private final AccountAddress sender; | ||
/** | ||
* The baker keys that will be configured for the account | ||
*/ | ||
private final BakerKeysJniOutput keys; | ||
} |
Oops, something went wrong.