|
|
|
@ -138,48 +138,57 @@ func GetNativeOperationsFromStakingTransaction( |
|
|
|
|
|
|
|
|
|
// expose delegated balance
|
|
|
|
|
if tx.StakingType() == stakingTypes.DirectiveDelegate { |
|
|
|
|
op2 := GetDelegateOperationForSubAccount(tx, operations[1]) |
|
|
|
|
op2 := getDelegateOperationForSubAccount(tx, operations[1]) |
|
|
|
|
return append(operations, op2), nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if tx.StakingType() == stakingTypes.DirectiveUndelegate { |
|
|
|
|
op2 := getUndelegateOperationForSubAccount(tx, operations[1], receipt) |
|
|
|
|
return append(operations, op2), nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return operations, nil |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getUndelegateOperationForSubAccount( |
|
|
|
|
tx *stakingTypes.StakingTransaction, delegateOperation *types.Operation, receipt *hmytypes.Receipt, |
|
|
|
|
) *types.Operation { |
|
|
|
|
// set sub account
|
|
|
|
|
validatorAddress := operations[1].Metadata["validatorAddress"] |
|
|
|
|
operations[1].Account.SubAccount = &types.SubAccountIdentifier{ |
|
|
|
|
validatorAddress := delegateOperation.Metadata["validatorAddress"] |
|
|
|
|
delegateOperation.Account.SubAccount = &types.SubAccountIdentifier{ |
|
|
|
|
Address: validatorAddress.(string), |
|
|
|
|
Metadata: map[string]interface{}{ |
|
|
|
|
SubAccountMetadataKey: Delegation, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
op2 := &types.Operation{ |
|
|
|
|
undelegateion := &types.Operation{ |
|
|
|
|
OperationIdentifier: &types.OperationIdentifier{ |
|
|
|
|
Index: operations[1].OperationIdentifier.Index + 1, |
|
|
|
|
Index: delegateOperation.OperationIdentifier.Index + 1, |
|
|
|
|
}, |
|
|
|
|
Type: tx.StakingType().String(), |
|
|
|
|
Status: GetTransactionStatus(tx, receipt), |
|
|
|
|
Account: &types.AccountIdentifier{ |
|
|
|
|
Address: operations[1].Account.Address, |
|
|
|
|
Address: delegateOperation.Account.Address, |
|
|
|
|
SubAccount: &types.SubAccountIdentifier{ |
|
|
|
|
Address: validatorAddress.(string), |
|
|
|
|
Metadata: map[string]interface{}{ |
|
|
|
|
SubAccountMetadataKey: UnDelegation, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
Metadata: operations[1].Account.Metadata, |
|
|
|
|
Metadata: delegateOperation.Account.Metadata, |
|
|
|
|
}, |
|
|
|
|
Amount: operations[1].Amount, |
|
|
|
|
Metadata: operations[1].Metadata, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return append(operations, op2), nil |
|
|
|
|
Amount: delegateOperation.Amount, |
|
|
|
|
Metadata: delegateOperation.Metadata, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return operations, nil |
|
|
|
|
|
|
|
|
|
return undelegateion |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func GetDelegateOperationForSubAccount(tx *stakingTypes.StakingTransaction, delegateOperation *types.Operation) *types.Operation { |
|
|
|
|
func getDelegateOperationForSubAccount( |
|
|
|
|
tx *stakingTypes.StakingTransaction, delegateOperation *types.Operation, |
|
|
|
|
) *types.Operation { |
|
|
|
|
amt, _ := new(big.Int).SetString(delegateOperation.Amount.Value, 10) |
|
|
|
|
delegateAmt := new(big.Int).Sub(new(big.Int).SetUint64(0), amt) |
|
|
|
|
validatorAddress := delegateOperation.Metadata["validatorAddress"] |
|
|
|
@ -216,12 +225,12 @@ func GetDelegateOperationForSubAccount(tx *stakingTypes.StakingTransaction, dele |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetSideEffectOperationsFromUndelegationPayouts from the given payouts.
|
|
|
|
|
// getSideEffectOperationsFromUndelegationPayouts from the given payouts.
|
|
|
|
|
// If the startingOperationIndex is provided, all operations will be indexed starting from the given operation index.
|
|
|
|
|
func GetSideEffectOperationsFromUndelegationPayouts( |
|
|
|
|
func getSideEffectOperationsFromUndelegationPayouts( |
|
|
|
|
payouts *hmy.UndelegationPayouts, startingOperationIndex *int64, |
|
|
|
|
) ([]*types.Operation, *types.Error) { |
|
|
|
|
return getSideEffectOperationsFromUndelegationPayouts( |
|
|
|
|
return getSideEffectOperationsFromUndelegationPayoutsMap( |
|
|
|
|
payouts, common.UndelegationPayoutOperation, startingOperationIndex, |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
@ -429,8 +438,6 @@ func getCrossShardSenderTransferNativeOperations( |
|
|
|
|
var opIndex int64 |
|
|
|
|
if startingOperationIndex != nil { |
|
|
|
|
opIndex = *startingOperationIndex |
|
|
|
|
} else { |
|
|
|
|
opIndex = 0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return []*types.Operation{ |
|
|
|
@ -451,7 +458,7 @@ func getCrossShardSenderTransferNativeOperations( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// delegator address => validator address => amount
|
|
|
|
|
func getSideEffectOperationsFromUndelegationPayouts( |
|
|
|
|
func getSideEffectOperationsFromUndelegationPayoutsMap( |
|
|
|
|
undelegationPayouts *hmy.UndelegationPayouts, opType string, startingOperationIndex *int64, |
|
|
|
|
) ([]*types.Operation, *types.Error) { |
|
|
|
|
var opIndex int64 |
|
|
|
@ -498,7 +505,7 @@ func getSideEffectOperationsFromUndelegationPayouts( |
|
|
|
|
return operations, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// getOperationAndTotalAmountFromUndelegationMap is a helper for getSideEffectOperationsFromUndelegationPayouts which actually
|
|
|
|
|
// getOperationAndTotalAmountFromUndelegationMap is a helper for getSideEffectOperationsFromUndelegationPayoutsMap which actually
|
|
|
|
|
// has some side effect(opIndex will be increased by this function) so be careful while using for other purpose
|
|
|
|
|
func getOperationAndTotalAmountFromUndelegationMap( |
|
|
|
|
delegator ethcommon.Address, opIndex *int64, relatedOpIdentifier *types.OperationIdentifier, opType string, |
|
|
|
|