add SerializeClaimFromJSON , DecodeAddress, and EncodeAddress to python binding

This commit is contained in:
Jack Robison 2017-11-27 10:25:04 -05:00
parent 6d169425d1
commit cdaf3ac682
No known key found for this signature in database
GPG key ID: 284699E7404E3CFF

View file

@ -1,8 +1,10 @@
package main package main
import ( import (
"../address"
"../claim" "../claim"
"C" "C"
"encoding/hex"
) )
//export VerifySignature //export VerifySignature
@ -19,23 +21,58 @@ func VerifySignature(claimHex string, certificateHex string, claimAddress string
if err != nil { if err != nil {
return false return false
} }
if result == false { return result
return false
}
return true
} }
//export DecodeClaimHex //export DecodeClaimHex
func DecodeClaimHex(claimHex string, blockchainName string) *C.char { func DecodeClaimHex(claimHex string, blockchainName string) *C.char {
decodedClaim, err := claim.DecodeClaimHex(claimHex, blockchainName) decodedClaim, err := claim.DecodeClaimHex(claimHex, blockchainName)
if err != nil { if err != nil {
return C.CString("decode error") return C.CString("decode error: " + err.Error())
} }
decoded, err := decodedClaim.RenderJSON() decoded, err := decodedClaim.RenderJSON()
if err != nil { if err != nil {
return C.CString("encode error") return C.CString("encode error: " + err.Error())
} }
return C.CString(decoded) return C.CString(decoded)
} }
//export SerializeClaimFromJSON
func SerializeClaimFromJSON(claimJSON string, blockchainName string) *C.char {
decodedClaim, err := claim.DecodeClaimJSON(claimJSON, blockchainName)
if err != nil {
return C.CString("decode error: " + err.Error())
}
SerializedHex, err := decodedClaim.SerializedHexString()
if err != nil {
return C.CString("encode error: " + err.Error())
}
return C.CString(SerializedHex)
}
//export DecodeAddress
func DecodeAddress(addressString string, blockchainName string) *C.char {
addressBytes, err := address.DecodeAddress(addressString, blockchainName)
if err != nil {
return C.CString("error: " + err.Error())
}
return C.CString(hex.EncodeToString(addressBytes[:]))
}
//export EncodeAddress
func EncodeAddress(addressChars string, blockchainName string) *C.char {
addressBytes := [25]byte{}
if len(addressChars) != 25 {
return C.CString("error: address is not 25 bytes")
}
for i := range addressBytes {
addressBytes[i] = byte(addressChars[i])
}
encodedAddress, err := address.EncodeAddress(addressBytes, blockchainName)
if err != nil {
return C.CString("error: " + err.Error())
}
return C.CString(encodedAddress)
}
func main() {} func main() {}