-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from tonkeeper/staking-actions
Add DepositStake and RecoverStake actions
- Loading branch information
Showing
14 changed files
with
774 additions
and
15 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
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
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,118 @@ | ||
package bath | ||
|
||
import ( | ||
"github.com/tonkeeper/opentonapi/pkg/blockchain/config" | ||
"github.com/tonkeeper/tongo" | ||
"github.com/tonkeeper/tongo/abi" | ||
) | ||
|
||
type BubbleDepositStake struct { | ||
Staker tongo.AccountID | ||
Amount int64 | ||
Success bool | ||
} | ||
|
||
func (ds BubbleDepositStake) ToAction() *Action { | ||
return &Action{ | ||
DepositStake: &DepositStakeAction{ | ||
Amount: ds.Amount, | ||
Elector: config.ElectorAddress(), | ||
Staker: ds.Staker, | ||
}, | ||
Success: ds.Success, | ||
Type: DepositStake, | ||
} | ||
} | ||
|
||
func FindDepositStake(bubble *Bubble) bool { | ||
bubbleTx, ok := bubble.Info.(BubbleTx) | ||
if !ok { | ||
return false | ||
} | ||
if !bubbleTx.operation(abi.ElectorNewStakeMsgOp) { | ||
return false | ||
} | ||
if bubbleTx.account.Address != config.ElectorAddress() { | ||
return false | ||
} | ||
stake := BubbleDepositStake{ | ||
Amount: bubbleTx.inputAmount, | ||
Staker: bubbleTx.inputFrom.Address, | ||
} | ||
newBubble := Bubble{ | ||
Accounts: bubble.Accounts, | ||
ValueFlow: bubble.ValueFlow, | ||
} | ||
newBubble.Children = ProcessChildren(bubble.Children, | ||
func(child *Bubble) *Merge { | ||
confirmation, ok := child.Info.(BubbleTx) | ||
if !ok { | ||
return nil | ||
} | ||
if !confirmation.operation(abi.ElectorNewStakeConfirmationMsgOp) { | ||
return nil | ||
} | ||
stake.Success = true | ||
newBubble.ValueFlow.Merge(child.ValueFlow) | ||
return &Merge{children: child.Children} | ||
}) | ||
newBubble.Info = stake | ||
*bubble = newBubble | ||
return true | ||
} | ||
|
||
type BubbleRecoverStake struct { | ||
Staker tongo.AccountID | ||
Amount int64 | ||
Success bool | ||
} | ||
|
||
func (b BubbleRecoverStake) ToAction() *Action { | ||
return &Action{ | ||
RecoverStake: &RecoverStakeAction{ | ||
Amount: b.Amount, | ||
Elector: config.ElectorAddress(), | ||
Staker: b.Staker, | ||
}, | ||
Success: b.Success, | ||
Type: RecoverStake, | ||
} | ||
} | ||
|
||
func FindRecoverStake(bubble *Bubble) bool { | ||
bubbleTx, ok := bubble.Info.(BubbleTx) | ||
if !ok { | ||
return false | ||
} | ||
if !bubbleTx.operation(abi.ElectorRecoverStakeRequestMsgOp) { | ||
return false | ||
} | ||
if bubbleTx.account.Address != config.ElectorAddress() { | ||
return false | ||
} | ||
recoverStake := BubbleRecoverStake{ | ||
Amount: bubbleTx.inputAmount, | ||
Staker: bubbleTx.inputFrom.Address, | ||
} | ||
newBubble := Bubble{ | ||
Accounts: bubble.Accounts, | ||
ValueFlow: bubble.ValueFlow, | ||
} | ||
newBubble.Children = ProcessChildren(bubble.Children, | ||
func(child *Bubble) *Merge { | ||
response, ok := child.Info.(BubbleTx) | ||
if !ok { | ||
return nil | ||
} | ||
if !response.operation(abi.ElectorRecoverStakeResponseMsgOp) { | ||
return nil | ||
} | ||
recoverStake.Success = true | ||
newBubble.ValueFlow.Merge(child.ValueFlow) | ||
return &Merge{children: child.Children} | ||
}) | ||
newBubble.Info = recoverStake | ||
*bubble = newBubble | ||
return true | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/tonkeeper/tongo" | ||
) | ||
|
||
func ElectorAddress() tongo.AccountID { | ||
// TODO: read from the blockchain config | ||
return tongo.MustParseAccountID("Ef8zMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzM0vF") | ||
} |
Oops, something went wrong.