SignedTransaction.go
package model
import (
"errors"
"github.com/Saseul/util"
)
type SignedTransaction struct {
SignedData
}
func NewSignedTransaction(item map[string]interface{}) *SignedTransaction {
st := &SignedTransaction{
SignedData: SignedData{
Data: item["transaction"].(map[string]interface{}),
PublicKey: item["public_key"].(string),
Signature: item["signature"].(string),
Cid: item["transaction"].(map[string]interface{})["cid"].(string),
Type: item["transaction"].(map[string]interface{})["type"].(string),
Timestamp: int64(item["transaction"].(map[string]interface{})["timestamp"].(float64)),
Attributes: make(map[string]interface{}),
CachedUniversal: make(map[string]interface{}),
CachedLocal: make(map[string]interface{}),
},
}
st.Hash = st.Hash()
return st
}
func (st *SignedTransaction) Validity() (bool, error) {
if st.Data == nil {
return false, errors.New("The signed transaction must contain the 'transaction' parameter.")
}
if st.PublicKey == "" {
return false, errors.New("The signed transaction must contain the 'public_key' parameter.")
}
if _, ok := st.Data["public_key"].(string); !ok {
return false, errors.New("Parameter 'public_key' must be of string type.")
}
if !util.SignerKeyValidity(st.PublicKey) {
return false, errors.New("Invalid public key: " + st.PublicKey)
}
if st.Signature == "" {
return false, errors.New("The signed transaction must contain the 'signature' parameter.")
}
if _, ok := st.Data["signature"].(string); !ok {
return false, errors.New("Parameter 'signature' must be of string type.")
}
if st.Type == "" {
return false, errors.New("The signed transaction must contain the 'transaction.type' parameter.")
}
if _, ok := st.Data["type"].(string); !ok {
return false, errors.New("Parameter 'transaction.type' must be of string type.")
}
if st.Timestamp == 0 {
return false, errors.New("The signed transaction must contain the 'transaction.timestamp' parameter.")
}
if _, ok := st.Data["timestamp"].(float64); !ok {
return false, errors.New("Parameter 'transaction.timestamp' must be of float64 type.")
}
if !util.SignerSignatureValidity(st.Hash, st.PublicKey, st.Signature) {
return false, errors.New("Invalid signature: " + st.Signature + " (transaction hash: " + st.Hash + ")")
}
return true, nil
}
func (st *SignedTransaction) Obj() map[string]interface{} {
return map[string]interface{}{
"transaction": st.Data,
"public_key": st.PublicKey,
"signature": st.Signature,
}
}SignedTransaction ꡬ쑰체
SignedTransaction ꡬ쑰체NewSignedTransaction ν¨μ
NewSignedTransaction ν¨μValidity ν¨μ
Validity ν¨μObj ν¨μ
Obj ν¨μμ 체 μ½λ μμ
Last updated