Skip to content

Commit

Permalink
Merge pull request #2687 from planetarium/chore/apply-dynamic-unbondi…
Browse files Browse the repository at this point in the history
…ng-period

Apply dynamic unbonding period
  • Loading branch information
OnedgeLee authored Jan 17, 2025
2 parents 5137098 + e5f5bec commit 8573385
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 59 deletions.
72 changes: 14 additions & 58 deletions NineChronicles.Headless/BlockChainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,18 +357,6 @@ public UnaryResult<byte[]> GetBalanceByStateRootHash(
return new UnaryResult<byte[]>(encoded);
}

public UnaryResult<byte[]> GetUnbondClaimableHeightByBlockHash(
byte[] blockHashBytes, byte[] addressBytes)
{
var blockHash = new BlockHash(blockHashBytes);
var address = new Address(addressBytes);
var worldState = _worldStateRepository.GetWorldState(blockHash);
var result = GetUnbondClaimableHeight(worldState, address);

byte[] encoded = _codec.Encode(result);
return new UnaryResult<byte[]>(encoded);
}

public UnaryResult<byte[]> GetUnbondClaimableHeightByStateRootHash(
byte[] stateRootHashBytes, byte[] addressBytes)
{
Expand All @@ -381,18 +369,6 @@ public UnaryResult<byte[]> GetUnbondClaimableHeightByStateRootHash(
return new UnaryResult<byte[]>(encoded);
}

public UnaryResult<byte[]> GetClaimableRewardsByBlockHash(
byte[] blockHashBytes, byte[] addressBytes)
{
var blockHash = new BlockHash(blockHashBytes);
var address = new Address(addressBytes);
var worldState = _worldStateRepository.GetWorldState(blockHash);
var result = GetClaimableRewards(worldState, address);

byte[] encoded = _codec.Encode(result);
return new UnaryResult<byte[]>(encoded);
}

public UnaryResult<byte[]> GetClaimableRewardsByStateRootHash(
byte[] stateRootHashBytes, byte[] addressBytes)
{
Expand All @@ -405,18 +381,6 @@ public UnaryResult<byte[]> GetClaimableRewardsByStateRootHash(
return new UnaryResult<byte[]>(encoded);
}

public UnaryResult<byte[]> GetDelegationInfoByBlockHash(
byte[] blockHashBytes, byte[] addressBytes)
{
var blockHash = new BlockHash(blockHashBytes);
var address = new Address(addressBytes);
var worldState = _worldStateRepository.GetWorldState(blockHash);
var result = GetDelegationInfo(worldState, address);

byte[] encoded = _codec.Encode(result);
return new UnaryResult<byte[]>(encoded);
}

public UnaryResult<byte[]> GetDelegationInfoByStateRootHash(
byte[] stateRootHashBytes, byte[] addressBytes)
{
Expand All @@ -429,18 +393,6 @@ public UnaryResult<byte[]> GetDelegationInfoByStateRootHash(
return new UnaryResult<byte[]>(encoded);
}

public UnaryResult<byte[]> GetStakedByBlockHash(
byte[] blockHashBytes, byte[] addressBytes)
{
var blockHash = new BlockHash(blockHashBytes);
var address = new Address(addressBytes);
var worldState = _worldStateRepository.GetWorldState(blockHash);
var result = GetStaked(worldState, address);

byte[] encoded = _codec.Encode(result);
return new UnaryResult<byte[]>(encoded);
}

public UnaryResult<byte[]> GetStakedByStateRootHash(
byte[] stateRootHashBytes, byte[] addressBytes)
{
Expand Down Expand Up @@ -546,16 +498,20 @@ private static IValue GetUnbondClaimableHeight(IWorldState worldState, Address a
var repository = new GuildRepository(new World(worldState), new HallowActionContext { });
try
{
var guildAddress = repository.GetGuildParticipant(address).GuildAddress;
var validatorAddress = repository.GetGuild(guildAddress).ValidatorAddress;
var guildDelegatee = repository.GetDelegatee(validatorAddress);
var unbondLockIn = repository.GetUnbondLockIn(guildDelegatee, address);
var unbondClaimableHeight = unbondLockIn.LowestExpireHeight;
return new Integer(unbondClaimableHeight);
}
catch (FailedLoadStateException)
{
return new Integer(-1L);
var delegator = repository.GetDelegator(address);
var expireHeights = delegator.UnbondingRefs
.Select(r => UnbondingFactory.GetUnbondingFromRef(r, repository))
.Where(u => u is UnbondLockIn)
.Select(u => u.LowestExpireHeight);

if (expireHeights.Any())
{
return new Integer(expireHeights.Min());
}
else
{
return new Integer(-1L);
}
}
catch (Exception e)
{
Expand Down

0 comments on commit 8573385

Please sign in to comment.