2017-12-04 21:36:11 +00:00
|
|
|
package contract_summary
|
2017-11-14 15:14:34 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2018-01-06 20:31:53 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
2017-11-29 15:31:23 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2017-11-14 15:14:34 +00:00
|
|
|
)
|
|
|
|
|
2017-12-04 16:17:13 +00:00
|
|
|
func GenerateConsoleOutput(summary ContractSummary) string {
|
2017-11-14 15:14:34 +00:00
|
|
|
return fmt.Sprintf(template(),
|
|
|
|
summary.ContractHash,
|
|
|
|
summary.NumberOfTransactions,
|
|
|
|
transactionToString(summary.LastTransaction),
|
2017-11-27 22:18:42 +00:00
|
|
|
attributesString(summary),
|
2017-11-14 15:14:34 +00:00
|
|
|
)
|
|
|
|
}
|
2017-11-28 16:45:21 +00:00
|
|
|
|
2017-11-14 15:14:34 +00:00
|
|
|
func template() string {
|
|
|
|
return `********************Contract Summary***********************
|
2017-11-27 14:54:30 +00:00
|
|
|
HASH: %v
|
|
|
|
NUMBER OF TRANSACTIONS: %d
|
|
|
|
LAST TRANSACTION:
|
|
|
|
%s
|
2017-11-27 22:18:42 +00:00
|
|
|
ATTRIBUTES:
|
|
|
|
%s
|
2017-11-14 15:14:34 +00:00
|
|
|
`
|
|
|
|
}
|
|
|
|
|
|
|
|
func transactionToString(transaction *core.Transaction) string {
|
|
|
|
if transaction == nil {
|
|
|
|
return "NONE"
|
|
|
|
} else {
|
|
|
|
return fmt.Sprintf(`Hash: %s
|
2017-11-27 14:54:30 +00:00
|
|
|
To: %s
|
|
|
|
From: %s`, transaction.Hash, transaction.To, transaction.From)
|
2017-11-14 15:14:34 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-27 22:18:42 +00:00
|
|
|
|
2017-12-04 16:17:13 +00:00
|
|
|
func attributesString(summary ContractSummary) string {
|
2017-11-27 22:18:42 +00:00
|
|
|
var formattedAttributes string
|
2017-11-28 16:45:21 +00:00
|
|
|
for _, attribute := range summary.Attributes {
|
|
|
|
formattedAttributes += formatAttribute(attribute.Name, summary) + "\n" + " "
|
2017-11-27 22:18:42 +00:00
|
|
|
}
|
|
|
|
return formattedAttributes
|
|
|
|
}
|
|
|
|
|
2017-12-04 16:17:13 +00:00
|
|
|
func formatAttribute(attributeName string, summary ContractSummary) string {
|
2017-11-29 15:31:23 +00:00
|
|
|
var stringResult string
|
|
|
|
result := summary.GetStateAttribute(attributeName)
|
|
|
|
switch t := result.(type) {
|
|
|
|
case common.Address:
|
|
|
|
ca := result.(common.Address)
|
2017-11-30 16:23:01 +00:00
|
|
|
stringResult = fmt.Sprintf("%s: %v", attributeName, ca.Hex())
|
2017-11-29 15:31:23 +00:00
|
|
|
default:
|
|
|
|
_ = t
|
2017-11-30 16:23:01 +00:00
|
|
|
stringResult = fmt.Sprintf("%s: %v", attributeName, result)
|
2017-11-29 15:31:23 +00:00
|
|
|
}
|
|
|
|
return stringResult
|
2017-11-27 22:18:42 +00:00
|
|
|
}
|