-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d26e1b
commit 7b1c01d
Showing
15 changed files
with
238 additions
and
38 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
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,98 @@ | ||
package schedulor | ||
|
||
import ( | ||
"AAStarCommunity/EthPaymaster_BackService/common/global_const" | ||
"AAStarCommunity/EthPaymaster_BackService/common/price_compoent" | ||
"AAStarCommunity/EthPaymaster_BackService/config" | ||
"AAStarCommunity/EthPaymaster_BackService/sponsor_manager" | ||
"github.com/ethereum/go-ethereum" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
"github.com/sirupsen/logrus" | ||
"math/big" | ||
) | ||
|
||
func AddListener(client ethclient.Client, network global_const.Network) { | ||
entryPointAddress, _ := config.GetSupportEntryPoints(network) | ||
if entryPointAddress == nil { | ||
logrus.Debugf("Not Support Network %v", network) | ||
return | ||
} | ||
for _, address := range entryPointAddress.ToSlice() { | ||
contractAddress := common.HexToAddress(address) | ||
query := ethereum.FilterQuery{ | ||
Addresses: []common.Address{contractAddress}, | ||
} | ||
sub, err := client.SubscribeFilterLogs(nil, query, nil) | ||
if err != nil { | ||
logrus.Errorf("SubscribeFilterLogs failed: %v", err) | ||
return | ||
} | ||
logs := make(chan types.Log) | ||
go func() { | ||
for { | ||
select { | ||
case err := <-sub.Err(): | ||
logrus.Errorf("SubscribeFilterLogs failed: %v", err) | ||
return | ||
case vLog := <-logs: | ||
if vLog.Removed { | ||
continue | ||
} | ||
//TODO | ||
//UserOpEventComunicate(network, ContractUserOperationEvent{}) | ||
} | ||
} | ||
}() | ||
//TODO | ||
//client.SubscribeFilterLogs() | ||
} | ||
//TODO | ||
} | ||
|
||
type ContractUserOperationEvent struct { | ||
UserOpHash [32]byte | ||
Sender string | ||
Paymaster string | ||
Nonce *big.Int | ||
Success bool | ||
ActualGasCost *big.Int | ||
ActualGasUsed *big.Int | ||
Raw types.Log | ||
} | ||
|
||
func UserOpEventComunicate(network global_const.Network, event ContractUserOperationEvent) { | ||
paymasterAddressSet, _ := config.GetSupportPaymaster(network) | ||
if paymasterAddressSet == nil { | ||
logrus.Debugf("Not Support Network %v", network) | ||
return | ||
} | ||
if !paymasterAddressSet.Contains(event.Paymaster) { | ||
logrus.Debugf("UserOpEventComunicate: paymaster not support, %v", event.Paymaster) | ||
return | ||
} | ||
if !event.Success { | ||
err := sponsor_manager.ReleaseUserOpHashLock(event.UserOpHash[:]) | ||
if err != nil { | ||
logrus.Errorf("ReleaseUserOpHashLock failed: %v", err) | ||
} | ||
return | ||
} | ||
gasCostEther := new(big.Float).SetInt(event.ActualGasCost) | ||
gasCostEther = new(big.Float).Quo(gasCostEther, new(big.Float).SetInt64(1e18)) | ||
//logrus.Infof("UserOpEventComunicate: %v, %v, %v, %v", event.UserOpHash, event.Sender, event.ActualGasCost, gasCostEther) | ||
gasCostUsd, err := price_compoent.GetTokenCostInUsd(global_const.TokenTypeETH, gasCostEther) | ||
if err != nil { | ||
//TODO if is NetWorkError, need retry | ||
logrus.Errorf("GetTokenCostInUsd failed: %v", err) | ||
return | ||
} | ||
|
||
err = sponsor_manager.ReleaseBalanceWithActualCost(event.Sender, event.UserOpHash[:], network, gasCostUsd) | ||
if err != nil { | ||
//TODO if is NetWorkError, need retry | ||
logrus.Errorf("ReleaseBalanceWithActualCost failed: %v", err) | ||
return | ||
} | ||
} |
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
Oops, something went wrong.