Guest User

Untitled

a guest
Nov 19th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. //JS code
  2.  
  3. const {Transaction} = require('stellar-base')
  4.  
  5. const parsedTx = new Transaction('tx_envelope_encoded_as_XDR')
  6. console.log(parsedTx)
  7.  
  8. //GO code
  9.  
  10. import (
  11.  
  12. "bytes"
  13. "encoding/json"
  14. "fmt"
  15. "net/http"
  16. "github.com/stellar/go/xdr"
  17. "github.com/gorilla/mux"
  18.  
  19. )
  20.  
  21. func DecodeXDR(w http.ResponseWriter, r *http.Request) {
  22.  
  23. var OBJ model.TransactionCollectionBody
  24. err := json.NewDecoder(r.Body).Decode(&OBJ)
  25. if err != nil {
  26. w.WriteHeader(http.StatusBadRequest)
  27. json.NewEncoder(w).Encode("Error while Decoding the body")
  28. fmt.Println(err)
  29.  
  30. return
  31. }
  32.  
  33. // fmt.Println(OBJ)
  34.  
  35. // lol:=xdr.Value(OBJ.XDR)
  36.  
  37. var txe xdr.Transaction
  38. err = xdr.SafeUnmarshalBase64(XDRB64, &txe)
  39. if err != nil {
  40. fmt.Println(err)
  41. }
  42.  
  43. fmt.Println(txe)
  44.  
  45. //Output
  46. {{PublicKeyTypePublicKeyTypeEd25519 0xc042055d20} 200 2800572080062465 <nil> {MemoTypeMemoNone <nil> <nil> <nil> <nil>} [{<nil> {OperationTypeManageData <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> 0xc042174040 <nil>}} {<nil> {OperationTypeManageData <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> 0xc042174080 <nil>}}] {0}}
  47.  
  48. //Expected Output
  49.  
  50. { type: 'payment', destination: 'GCKUXI3JRJANYOF3AM35Z22FGUGYYUIEBPE5TTZ7P3G6XAEFGYZC2POM', asset: Asset { code: 'Blog', issuer: 'GDOPTRADBVWJR6BMB6H5ACQTAVUS6XMT53CDNAJZLOSTIUICIW57ISMF' }, amount: '10' }
  51.  
  52. { type: 'payment', destination: 'GCKUXI3JRJANYOF3AM35Z22FGUGYYUIEBPE5TTZ7P3G6XAEFGYZC2POM', asset: Asset { code: 'Blog', issuer: 'GDOPTRADBVWJR6BMB6H5ACQTAVUS6XMT53CDNAJZLOSTIUICIW57ISMF' }, amount: '10' }
  53.  
  54. { type: 'payment', destination: 'GCKUXI3JRJANYOF3AM35Z22FGUGYYUIEBPE5TTZ7P3G6XAEFGYZC2POM', asset: Asset { code: 'Blog', issuer: 'GDOPTRADBVWJR6BMB6H5ACQTAVUS6XMT53CDNAJZLOSTIUICIW57ISMF' }, amount: '10' }
Add Comment
Please, Sign In to add comment