diff --git a/api/converter_utils.go b/api/converter_utils.go index 26b519c75..dca2bcfb3 100644 --- a/api/converter_utils.go +++ b/api/converter_utils.go @@ -160,7 +160,7 @@ func msigToTransactionMsig(msig crypto.MultisigSig) *generated.TransactionSignat subsigs := make([]generated.TransactionSignatureMultisigSubsignature, 0) for _, subsig := range msig.Subsigs { subsigs = append(subsigs, generated.TransactionSignatureMultisigSubsignature{ - PublicKey: bytePtr(subsig.Key[:]), + PublicKey: byteSliceOmitZeroPtr(subsig.Key[:]), Signature: sigToTransactionSig(subsig.Sig), }) } @@ -317,11 +317,11 @@ func signedTxnWithAdToTransaction(stxn *transactions.SignedTxnWithAD, extra rowD case protocol.KeyRegistrationTx: k := generated.TransactionKeyreg{ NonParticipation: boolPtr(stxn.Txn.Nonparticipation), - SelectionParticipationKey: bytePtr(stxn.Txn.SelectionPK[:]), + SelectionParticipationKey: byteSliceOmitZeroPtr(stxn.Txn.SelectionPK[:]), VoteFirstValid: uint64Ptr(uint64(stxn.Txn.VoteFirst)), VoteLastValid: uint64Ptr(uint64(stxn.Txn.VoteLast)), VoteKeyDilution: uint64Ptr(stxn.Txn.VoteKeyDilution), - VoteParticipationKey: bytePtr(stxn.Txn.VotePK[:]), + VoteParticipationKey: byteSliceOmitZeroPtr(stxn.Txn.VotePK[:]), } keyreg = &k case protocol.AssetConfigTx: @@ -332,15 +332,15 @@ func signedTxnWithAdToTransaction(stxn *transactions.SignedTxnWithAD, extra rowD DefaultFrozen: boolPtr(stxn.Txn.AssetParams.DefaultFrozen), Freeze: addrPtr(stxn.Txn.AssetParams.Freeze), Manager: addrPtr(stxn.Txn.AssetParams.Manager), - MetadataHash: bytePtr(stxn.Txn.AssetParams.MetadataHash[:]), + MetadataHash: byteSliceOmitZeroPtr(stxn.Txn.AssetParams.MetadataHash[:]), Name: strPtr(util.PrintableUTF8OrEmpty(stxn.Txn.AssetParams.AssetName)), - NameB64: bytePtr([]byte(stxn.Txn.AssetParams.AssetName)), + NameB64: byteSlicePtr([]byte(stxn.Txn.AssetParams.AssetName)), Reserve: addrPtr(stxn.Txn.AssetParams.Reserve), Total: stxn.Txn.AssetParams.Total, UnitName: strPtr(util.PrintableUTF8OrEmpty(stxn.Txn.AssetParams.UnitName)), - UnitNameB64: bytePtr([]byte(stxn.Txn.AssetParams.UnitName)), + UnitNameB64: byteSlicePtr([]byte(stxn.Txn.AssetParams.UnitName)), Url: strPtr(util.PrintableUTF8OrEmpty(stxn.Txn.AssetParams.URL)), - UrlB64: bytePtr([]byte(stxn.Txn.AssetParams.URL)), + UrlB64: byteSlicePtr([]byte(stxn.Txn.AssetParams.URL)), } config := generated.TransactionAssetConfig{ AssetId: uint64Ptr(uint64(stxn.Txn.ConfigAsset)), @@ -389,8 +389,8 @@ func signedTxnWithAdToTransaction(stxn *transactions.SignedTxnWithAD, extra rowD Accounts: &accts, ApplicationArgs: &args, ApplicationId: uint64(stxn.Txn.ApplicationID), - ApprovalProgram: bytePtr(stxn.Txn.ApprovalProgram), - ClearStateProgram: bytePtr(stxn.Txn.ClearStateProgram), + ApprovalProgram: byteSliceOmitZeroPtr(stxn.Txn.ApprovalProgram), + ClearStateProgram: byteSliceOmitZeroPtr(stxn.Txn.ClearStateProgram), ForeignApps: &apps, ForeignAssets: &assets, GlobalStateSchema: &generated.StateSchema{ @@ -491,12 +491,12 @@ func signedTxnWithAdToTransaction(stxn *transactions.SignedTxnWithAD, extra rowD RoundTime: uint64Ptr(uint64(extra.RoundTime)), Fee: stxn.Txn.Fee.Raw, FirstValid: uint64(stxn.Txn.FirstValid), - GenesisHash: bytePtr(stxn.SignedTxn.Txn.GenesisHash[:]), + GenesisHash: byteSliceOmitZeroPtr(stxn.SignedTxn.Txn.GenesisHash[:]), GenesisId: strPtr(stxn.SignedTxn.Txn.GenesisID), - Group: bytePtr(stxn.Txn.Group[:]), + Group: byteSliceOmitZeroPtr(stxn.Txn.Group[:]), LastValid: uint64(stxn.Txn.LastValid), - Lease: bytePtr(stxn.Txn.Lease[:]), - Note: bytePtr(stxn.Txn.Note[:]), + Lease: byteSliceOmitZeroPtr(stxn.Txn.Lease[:]), + Note: byteSliceOmitZeroPtr(stxn.Txn.Note[:]), Sender: stxn.Txn.Sender.String(), ReceiverRewards: uint64Ptr(stxn.ReceiverRewards.Raw), CloseRewards: uint64Ptr(stxn.CloseRewards.Raw), diff --git a/api/handlers.go b/api/handlers.go index cf66e569a..a9a3fac39 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -615,13 +615,13 @@ func (si *ServerImplementation) fetchAssets(ctx context.Context, options idb.Ass Name: strPtr(util.PrintableUTF8OrEmpty(row.Params.AssetName)), UnitName: strPtr(util.PrintableUTF8OrEmpty(row.Params.UnitName)), Url: strPtr(util.PrintableUTF8OrEmpty(row.Params.URL)), - NameB64: bytePtr([]byte(row.Params.AssetName)), - UnitNameB64: bytePtr([]byte(row.Params.UnitName)), - UrlB64: bytePtr([]byte(row.Params.URL)), + NameB64: byteSlicePtr([]byte(row.Params.AssetName)), + UnitNameB64: byteSlicePtr([]byte(row.Params.UnitName)), + UrlB64: byteSlicePtr([]byte(row.Params.URL)), Total: row.Params.Total, Decimals: uint64(row.Params.Decimals), DefaultFrozen: boolPtr(row.Params.DefaultFrozen), - MetadataHash: bytePtr(mdhash), + MetadataHash: byteSliceOmitZeroPtr(mdhash), Clawback: strPtr(row.Params.Clawback.String()), Reserve: strPtr(row.Params.Reserve.String()), Freeze: strPtr(row.Params.Freeze.String()), diff --git a/api/pointer_utils.go b/api/pointer_utils.go index 0aa08f9ee..77dbf2c6b 100644 --- a/api/pointer_utils.go +++ b/api/pointer_utils.go @@ -51,11 +51,17 @@ func uint64PtrOrNil(x uint64) *uint64 { return &x } -func bytePtr(x []byte) *[]byte { +func byteSlicePtr(x []byte) *[]byte { if len(x) == 0 { return nil } + xx := make([]byte, len(x)) + copy(xx, x) + return &xx +} + +func byteSliceOmitZeroPtr(x []byte) *[]byte { // Don't return if it's all zero. for _, v := range x { if v != 0 { diff --git a/idb/postgres/postgres.go b/idb/postgres/postgres.go index 9e4db186f..a1fd05a9c 100644 --- a/idb/postgres/postgres.go +++ b/idb/postgres/postgres.go @@ -1192,12 +1192,12 @@ func (db *IndexerDb) yieldAccountsThread(req *getAccountsRequest) { Decimals: uint64(ap.Decimals), DefaultFrozen: boolPtr(ap.DefaultFrozen), UnitName: stringPtr(util.PrintableUTF8OrEmpty(ap.UnitName)), - UnitNameB64: baPtr([]byte(ap.UnitName)), + UnitNameB64: byteSlicePtr([]byte(ap.UnitName)), Name: stringPtr(util.PrintableUTF8OrEmpty(ap.AssetName)), - NameB64: baPtr([]byte(ap.AssetName)), + NameB64: byteSlicePtr([]byte(ap.AssetName)), Url: stringPtr(util.PrintableUTF8OrEmpty(ap.URL)), - UrlB64: baPtr([]byte(ap.URL)), - MetadataHash: baPtr(ap.MetadataHash[:]), + UrlB64: byteSlicePtr([]byte(ap.URL)), + MetadataHash: byteSliceOmitZeroPtr(ap.MetadataHash[:]), Manager: addrStr(ap.Manager), Reserve: addrStr(ap.Reserve), Freeze: addrStr(ap.Freeze), @@ -1404,10 +1404,17 @@ func stringPtr(x string) *string { return out } -func baPtr(x []byte) *[]byte { +func byteSlicePtr(x []byte) *[]byte { if len(x) == 0 { return nil } + + xx := make([]byte, len(x)) + copy(xx, x) + return &xx +} + +func byteSliceOmitZeroPtr(x []byte) *[]byte { allzero := true for _, b := range x { if b != 0 {