Add abi file and the code to read it

pull/530/head
Rongjian Lan 6 years ago
parent cfb26943a2
commit ecd14ea0da
  1. 21
      api/service/staking/service.go
  2. 143
      contracts/StakeLockContract.json

@ -2,7 +2,9 @@ package staking
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
"github.com/ethereum/go-ethereum/accounts/abi"
"math/big" "math/big"
"os"
"time" "time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -98,6 +100,14 @@ func (s *Service) IsStaked() bool {
// DoService does staking. // DoService does staking.
func (s *Service) DoService() { func (s *Service) DoService() {
utils.GetLogInstance().Info("Trying to send a staking transaction.") utils.GetLogInstance().Info("Trying to send a staking transaction.")
abi, err := s.getStakeLockContractABI()
if err != nil {
utils.GetLogInstance().Error("Failed to generate staking contract's ABI", "error", err)
} else {
utils.GetLogInstance().Info("Generated staking contract's ABI", "abi", abi)
}
// TODO: use abi to generate staking transaction.
if s.beaconChain == nil { if s.beaconChain == nil {
utils.GetLogInstance().Info("Can not send a staking transaction because of nil beacon chain.") utils.GetLogInstance().Info("Can not send a staking transaction because of nil beacon chain.")
return return
@ -110,6 +120,17 @@ func (s *Service) DoService() {
} }
} }
func (s *Service) getStakeLockContractABI() (abi.ABI, error) {
f, err := os.Open("./contracts/StakeLockContract.json")
if err != nil {
if os.IsNotExist(err) {
return abi.ABI{}, err
}
}
defer f.Close()
return abi.JSON(f)
}
func (s *Service) getStakingInfo() *proto.StakingContractInfoResponse { func (s *Service) getStakingInfo() *proto.StakingContractInfoResponse {
address := crypto.PubkeyToAddress(s.accountKey.PublicKey) address := crypto.PubkeyToAddress(s.accountKey.PublicKey)
state, err := s.beaconChain.State() state, err := s.beaconChain.State()

@ -0,0 +1,143 @@
[
{
"constant": true,
"inputs": [],
"name": "listLockedAddresses",
"outputs": [
{
"name": "lockedAddresses",
"type": "address[]"
},
{
"name": "blockNums",
"type": "uint256[]"
},
{
"name": "lockPeriodCounts",
"type": "uint256[]"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_of",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"name": "balance",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "currentEpoch",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "unlock",
"outputs": [
{
"name": "unlockableTokens",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_of",
"type": "address"
}
],
"name": "getUnlockableTokens",
"outputs": [
{
"name": "unlockableTokens",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "lock",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": true,
"stateMutability": "payable",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_of",
"type": "address"
},
{
"indexed": false,
"name": "_amount",
"type": "uint256"
},
{
"indexed": false,
"name": "_epoch",
"type": "uint256"
}
],
"name": "Locked",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "account",
"type": "address"
},
{
"indexed": false,
"name": "index",
"type": "uint256"
}
],
"name": "Unlocked",
"type": "event"
}
]
Loading…
Cancel
Save