2018-03-31 04:07:42 +00:00
package collator
import (
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/sharding"
"github.com/ethereum/go-ethereum/sharding/client"
)
// joinCollatorPool checks if the account is a collator in the SMC. If
// the account is not in the set, it will deposit 100ETH into contract.
2018-03-31 18:25:39 +00:00
func joinCollatorPool ( c client . Client ) error {
2018-03-31 04:07:42 +00:00
2018-03-31 18:25:39 +00:00
log . Info ( "Joining collator pool" )
txOps , err := c . CreateTXOps ( sharding . DepositSize )
if err != nil {
return fmt . Errorf ( "unable to intiate the deposit transaction: %v" , err )
}
2018-03-31 04:07:42 +00:00
2018-03-31 18:25:39 +00:00
tx , err := c . SMCTransactor ( ) . Deposit ( txOps )
if err != nil {
return fmt . Errorf ( "unable to deposit eth and become a collator: %v" , err )
2018-03-31 04:07:42 +00:00
}
2018-03-31 18:25:39 +00:00
log . Info ( fmt . Sprintf ( "Deposited %dETH into contract with transaction hash: %s" , new ( big . Int ) . Div ( sharding . DepositSize , big . NewInt ( params . Ether ) ) , tx . Hash ( ) . String ( ) ) )
2018-03-31 04:07:42 +00:00
return nil
}