Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force stop contracts #449

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
l2mp_leasing.ride
bra1nsurfer committed Apr 19, 2024

Verified

This commit was signed with the committer’s verified signature.
commit e373dee40c9afbca20eef47fa63bedb44ce32bfb
28 changes: 28 additions & 0 deletions ride/l2mp_leasing.ride
Original file line number Diff line number Diff line change
@@ -394,8 +394,25 @@ func getSetNewPeriodLengthActions(newPeriodLength: Int) = {
}
}

### Force Stop check function
func isForceStopped() = {
let keyForceStopContract = ["%s", "forceStopContract"].makeString(SEP)
let forceStopAddressString = this.getString(keyForceStopContract).valueOrElse("")
let forceStopAddress = forceStopAddressString.addressFromString().valueOrElse(this)

let keyDisabledStatus = ["%s%s", "disabled", this.toString()].makeString(SEP)
let disabledStatus = forceStopAddress.getBoolean(keyDisabledStatus).valueOrElse(false)

if (disabledStatus == true)
then "Force stopped".throw()
else false
}
### End Force Stop function


@Callable(i)
func setNewPeriodLength(newPeriodLength: Int) = {
strict checkForceStop = isForceStopped()
strict checks = [
isInAdminList(i.caller.toString()) || "caller is not in adminList".throwErr()
]
@@ -405,6 +422,7 @@ func setNewPeriodLength(newPeriodLength: Int) = {

@Callable(i)
func setForceStopFlag(stop: Boolean) = {
strict checkForceStop = isForceStopped()
strict check = [
isInAdminList(i.caller.toString()) || "caller is not in adminList".throwErr()
]
@@ -422,6 +440,7 @@ func setForceStopFlag(stop: Boolean) = {
# _5 = current height
@Callable(i)
func getNodeDataREADONLY(nodeAddress: String) = {
strict checkForceStop = isForceStopped()
let (currentLease, nextLeased) = getLeasingNodeData(nodeAddress)

([], (currentPeriodHeight, currentLease, nextPeriodHeight, nextLeased, height))
@@ -435,6 +454,7 @@ func getNodeDataREADONLY(nodeAddress: String) = {
# _5 = current height
@Callable(i)
func getUserLeasingDataREADONLY(nodeAddress: String, userAddress: String) = {
strict checkForceStop = isForceStopped()
let (currentLease, nextLeased) = getUserLeasingData(nodeAddress, userAddress)

([], (currentPeriodHeight, currentLease, nextPeriodHeight, nextLeased, height))
@@ -449,6 +469,7 @@ func getUserLeasingDataREADONLY(nodeAddress: String, userAddress: String) = {
# _6 = current height
@Callable(i)
func getUserDataREADONLY(userAddress: String) = {
strict checkForceStop = isForceStopped()
let (toClaim, toUnlock) = getUserToClaimBalance(userAddress)
let userTotalLocked = getUserTotalLocked(userAddress)

@@ -457,39 +478,45 @@ func getUserDataREADONLY(userAddress: String) = {

@Callable(i)
func leaseByAddress(nodeAddress: String, userAddress: String) = {
strict checkForceStop = isForceStopped()
getStakeFromPaymentActions(nodeAddress, userAddress, i)
}

@Callable(i)
func lease(nodeAddress: String) = {
strict checkForceStop = isForceStopped()
let userAddress = i.caller.toString()

getStakeFromPaymentActions(nodeAddress, userAddress, i)
}

@Callable(i)
func leaseFromLocked(nodeAddress: String, amount: Int) = {
strict checkForceStop = isForceStopped()
let userAddress = i.caller.toString()

getStakeActions(nodeAddress, userAddress, amount, i)
}

@Callable(i)
func cancelLease(nodeAddress: String, amount: Int) = {
strict checkForceStop = isForceStopped()
let userAddress = i.caller.toString()

getUnstakeActions(nodeAddress, userAddress, amount)
}

@Callable(i)
func claim(amount: Int) = {
strict checkForceStop = isForceStopped()
let userAddress = i.caller.toString()

getClaimUnlockedActions(userAddress, amount)
}

@Callable(i)
func claimAll() = {
strict checkForceStop = isForceStopped()
let userAddress = i.caller.toString()
let (toClaim, toUnlock) = getUserToClaimBalance(userAddress)

@@ -506,6 +533,7 @@ func claimAll() = {
# Vote for txId that is allowed in Verifier
@Callable(i)
func voteForTxId(txId: String) = {
strict checkForceStop = isForceStopped()
let callerAddressString = toBase58String(i.caller.bytes)
let keyPrefix = keyAllowedTxIdVotePrefix(txId)
let result = [ StringEntry(keyAllowedTxId(), txId) ]