@@ -615,3 +615,147 @@ func (t *LedgerTransaction) NewMaxFee() (uint32, bool) {
615
615
func (t * LedgerTransaction ) Successful () bool {
616
616
return t .Result .Successful ()
617
617
}
618
+
619
+ func (t * LedgerTransaction ) GetTransactionV1Envelope () (xdr.TransactionV1Envelope , bool ) {
620
+ switch t .Envelope .Type {
621
+ case xdr .EnvelopeTypeEnvelopeTypeTx :
622
+ switch t .Envelope .Type {
623
+ case 2 :
624
+ return * t .Envelope .V1 , true
625
+ default :
626
+ return xdr.TransactionV1Envelope {}, false
627
+ }
628
+ case xdr .EnvelopeTypeEnvelopeTypeTxFeeBump :
629
+ return t .Envelope .MustFeeBump ().Tx .InnerTx .MustV1 (), true
630
+ default :
631
+ return xdr.TransactionV1Envelope {}, false
632
+ }
633
+ }
634
+
635
+ func (t * LedgerTransaction ) LedgerKeyHashesFromSorobanFootprint () []string {
636
+ var ledgerKeyHash []string
637
+
638
+ v1Envelope , ok := t .GetTransactionV1Envelope ()
639
+ if ! ok {
640
+ return ledgerKeyHash
641
+ }
642
+
643
+ for _ , ledgerKey := range v1Envelope .Tx .Ext .SorobanData .Resources .Footprint .ReadOnly {
644
+ ledgerKeyBase64 , err := xdr .MarshalBase64 (ledgerKey )
645
+ if err != nil {
646
+ panic (err )
647
+ }
648
+ if ledgerKeyBase64 != "" {
649
+ ledgerKeyHash = append (ledgerKeyHash , ledgerKeyBase64 )
650
+ }
651
+ }
652
+
653
+ for _ , ledgerKey := range v1Envelope .Tx .Ext .SorobanData .Resources .Footprint .ReadWrite {
654
+ ledgerKeyBase64 , err := xdr .MarshalBase64 (ledgerKey )
655
+ if err != nil {
656
+ panic (err )
657
+ }
658
+ if ledgerKeyBase64 != "" {
659
+ ledgerKeyHash = append (ledgerKeyHash , ledgerKeyBase64 )
660
+ }
661
+ }
662
+
663
+ return ledgerKeyHash
664
+ }
665
+
666
+ func (t * LedgerTransaction ) ContractCodeHashFromSorobanFootprint () (string , bool ) {
667
+ v1Envelope , ok := t .GetTransactionV1Envelope ()
668
+ if ! ok {
669
+ return "" , false
670
+ }
671
+ for _ , ledgerKey := range v1Envelope .Tx .Ext .SorobanData .Resources .Footprint .ReadOnly {
672
+ contractCode , ok := t .contractCodeFromContractData (ledgerKey )
673
+ if ! ok {
674
+ return "" , false
675
+ }
676
+ if contractCode != "" {
677
+ return contractCode , true
678
+ }
679
+ }
680
+
681
+ for _ , ledgerKey := range v1Envelope .Tx .Ext .SorobanData .Resources .Footprint .ReadWrite {
682
+ contractCode , ok := t .contractCodeFromContractData (ledgerKey )
683
+ if ! ok {
684
+ return "" , false
685
+ }
686
+ if contractCode != "" {
687
+ return contractCode , true
688
+ }
689
+ }
690
+
691
+ return "" , true
692
+ }
693
+
694
+ func (t * LedgerTransaction ) contractCodeFromContractData (ledgerKey xdr.LedgerKey ) (string , bool ) {
695
+ contractCode , ok := ledgerKey .GetContractCode ()
696
+ if ! ok {
697
+ return "" , false
698
+ }
699
+
700
+ codeHash , err := xdr .MarshalBase64 (contractCode .Hash )
701
+ if err != nil {
702
+ panic (err )
703
+ }
704
+
705
+ return codeHash , true
706
+ }
707
+
708
+ func (t * LedgerTransaction ) ContractIdFromTxEnvelope () (string , bool ) {
709
+ v1Envelope , ok := t .GetTransactionV1Envelope ()
710
+ if ! ok {
711
+ return "" , false
712
+ }
713
+ for _ , ledgerKey := range v1Envelope .Tx .Ext .SorobanData .Resources .Footprint .ReadWrite {
714
+ contractId , ok := t .contractIdFromContractData (ledgerKey )
715
+ if ! ok {
716
+ return "" , false
717
+ }
718
+
719
+ if contractId != "" {
720
+ return contractId , true
721
+ }
722
+ }
723
+
724
+ for _ , ledgerKey := range v1Envelope .Tx .Ext .SorobanData .Resources .Footprint .ReadOnly {
725
+ contractId , ok := t .contractIdFromContractData (ledgerKey )
726
+ if ! ok {
727
+ return "" , false
728
+ }
729
+
730
+ if contractId != "" {
731
+ return contractId , true
732
+ }
733
+ }
734
+
735
+ return "" , true
736
+ }
737
+
738
+ func (t * LedgerTransaction ) contractIdFromContractData (ledgerKey xdr.LedgerKey ) (string , bool ) {
739
+ contractData , ok := ledgerKey .GetContractData ()
740
+ if ! ok {
741
+ return "" , false
742
+ }
743
+ contractIdHash , ok := contractData .Contract .GetContractId ()
744
+ if ! ok {
745
+ return "" , false
746
+ }
747
+
748
+ var contractIdByte []byte
749
+ var contractId string
750
+ var err error
751
+ contractIdByte , err = contractIdHash .MarshalBinary ()
752
+ if err != nil {
753
+ panic (err )
754
+ }
755
+ contractId , err = strkey .Encode (strkey .VersionByteContract , contractIdByte )
756
+ if err != nil {
757
+ panic (err )
758
+ }
759
+
760
+ return contractId , true
761
+ }
0 commit comments