Skip to content

Commit

Permalink
rpc:api_service.go add gettx by contract api
Browse files Browse the repository at this point in the history
  • Loading branch information
fengzi committed May 8, 2018
1 parent dec6dcf commit e25246b
Show file tree
Hide file tree
Showing 5 changed files with 405 additions and 208 deletions.
13 changes: 13 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,19 @@ func (bc *BlockChain) GetTransaction(hash byteutils.Hash) (*Transaction, error)
return tx, nil
}

// GetContract return contract of given address
func (bc *BlockChain) GetContract(addr *Address) (state.Account, error) {
worldState, err := bc.TailBlock().WorldState().Clone()
if err != nil {
return nil, err
}
contract, err := CheckContract(addr, worldState)
if err != nil {
return nil, err
}
return contract, nil
}

// GasPrice returns the lowest transaction gas price.
func (bc *BlockChain) GasPrice() *util.Uint128 {
gasPrice := TransactionMaxGasPrice
Expand Down
25 changes: 25 additions & 0 deletions rpc/api_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,31 @@ func (s *APIService) GetTransactionReceipt(ctx context.Context, req *rpcpb.GetTr
return s.toTransactionResponse(tx)
}

// GetTransactionByContract get transaction info by the contract address
func (s *APIService) GetTransactionByContract(ctx context.Context, req *rpcpb.GetTransactionByContractRequest) (*rpcpb.TransactionResponse, error) {

neb := s.server.Neblet()

addr, err := core.AddressParse(req.GetAddress())
if err != nil {
return nil, err
}

contract, err := neb.BlockChain().GetContract(addr)
if err != nil {
return nil, err
}

hash := contract.BirthPlace()

tx, err := neb.BlockChain().GetTransaction(hash)
if err != nil {
return nil, err
}

return s.toTransactionResponse(tx)
}

func (s *APIService) toTransactionResponse(tx *core.Transaction) (*rpcpb.TransactionResponse, error) {
var (
status int32
Expand Down
Loading

0 comments on commit e25246b

Please sign in to comment.