Move type conversion to presenter
This commit is contained in:
+2
-17
@@ -31,22 +31,7 @@ func (blockchain *GethBlockchain) GetContractAttributes(contractHash string) (co
|
||||
return contractAttributes, nil
|
||||
}
|
||||
|
||||
func convertresult(result interface{}, attributeName string) *string {
|
||||
var stringResult = new(string)
|
||||
fmt.Println(fmt.Sprintf("%s: %v (%T)", attributeName, result, result))
|
||||
switch t := result.(type) {
|
||||
case common.Address:
|
||||
ca := result.(common.Address)
|
||||
*stringResult = fmt.Sprintf("%v", ca.Hex())
|
||||
default:
|
||||
_ = t
|
||||
*stringResult = fmt.Sprintf("%v", result)
|
||||
}
|
||||
return stringResult
|
||||
|
||||
}
|
||||
|
||||
func (blockchain *GethBlockchain) GetContractStateAttribute(contractHash string, attributeName string) (*string, error) {
|
||||
func (blockchain *GethBlockchain) GetContractStateAttribute(contractHash string, attributeName string) (interface{}, error) {
|
||||
boundContract, err := bindContract(common.HexToAddress(contractHash), blockchain.client, blockchain.client)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -56,7 +41,7 @@ func (blockchain *GethBlockchain) GetContractStateAttribute(contractHash string,
|
||||
if err != nil {
|
||||
return nil, ErrInvalidStateAttribute
|
||||
}
|
||||
return convertresult(result, attributeName), nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func bindContract(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor) (*bind.BoundContract, error) {
|
||||
|
||||
@@ -48,18 +48,6 @@ package geth_test
|
||||
// attribute := testing.FindAttribute(attributes, "unpause")
|
||||
// Expect(attribute).To(BeNil())
|
||||
// })
|
||||
//
|
||||
// It("temporarily filters out non-string attributes", func() {
|
||||
// config, _ := cfg.NewConfig("public")
|
||||
// blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
||||
// contractHash := "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07"
|
||||
//
|
||||
// attributes, err := blockchain.GetContractAttributes(contractHash)
|
||||
//
|
||||
// Expect(err).To(BeNil())
|
||||
// attribute := testing.FindAttribute(attributes, "decimals")
|
||||
// Expect(attribute).To(BeNil())
|
||||
// })
|
||||
// })
|
||||
//
|
||||
// Describe("Getting a contract attribute", func() {
|
||||
@@ -70,7 +58,7 @@ package geth_test
|
||||
//
|
||||
// name, err := blockchain.GetContractStateAttribute(contractHash, "name")
|
||||
//
|
||||
// Expect(*name).To(Equal("OMGToken"))
|
||||
// Expect(name).To(Equal("OMGToken"))
|
||||
// Expect(err).To(BeNil())
|
||||
// })
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user