MCPcopy Create free account
hub / github.com/DEROFDN/Engram / getMessages

Function getMessages

functions.go:1835–1905  ·  view source on GitHub ↗

Get a list of all message transactions and sort them by address

(h uint64)

Source from the content-addressed store, hash-verified

1833
1834// Get a list of all message transactions and sort them by address
1835func getMessages(h uint64) (result []string) {
1836 var zeroscid crypto.Hash
1837 messages := engram.Disk.Get_Payments_DestinationPort(zeroscid, uint64(1337), h)
1838
1839 for m := range messages {
1840 if messages[m].Incoming {
1841 if messages[m].Payload_RPC.HasValue(rpc.RPC_NEEDS_REPLYBACK_ADDRESS, rpc.DataString) {
1842 if messages[m].Payload_RPC.Value(rpc.RPC_NEEDS_REPLYBACK_ADDRESS, rpc.DataString).(string) == "" {
1843
1844 } else {
1845 height := int64(messages[m].Height)
1846 sender, _ := checkUsername(messages[m].Payload_RPC.Value(rpc.RPC_NEEDS_REPLYBACK_ADDRESS, rpc.DataString).(string), height)
1847 if sender == "" {
1848 addr, err := globals.ParseValidateAddress(messages[m].Payload_RPC.Value(rpc.RPC_NEEDS_REPLYBACK_ADDRESS, rpc.DataString).(string))
1849 if err != nil {
1850
1851 } else {
1852 sender = addr.String()
1853 for r := range result {
1854 if r > -1 && r < len(result) {
1855 if strings.Contains(result[r], sender+"~~~") {
1856 copy(result[r:], result[r+1:])
1857 result[len(result)-1] = ""
1858 result = result[:len(result)-1]
1859 }
1860 }
1861 }
1862 result = append(result, sender+"~~~")
1863 }
1864 } else {
1865 // Check for spoofing
1866 //if ring_member_exists(messages[m].TXID, sender) {
1867 for r := range result {
1868 if r > -1 && r < len(result) {
1869 //if strings.Contains(result[r], sender+"```"+messages[m].Payload_RPC.Value(rpc.RPC_NEEDS_REPLYBACK_ADDRESS, rpc.DataString).(string)) {
1870 if strings.Contains(result[r], sender+"~~~") {
1871 copy(result[r:], result[r+1:])
1872 result[len(result)-1] = ""
1873 result = result[:len(result)-1]
1874 }
1875 }
1876 }
1877 result = append(result, sender+"~~~"+messages[m].Payload_RPC.Value(rpc.RPC_NEEDS_REPLYBACK_ADDRESS, rpc.DataString).(string))
1878 //} else {
1879 // TODO: Add spoofing address to the ban list?
1880 //}
1881 }
1882 }
1883 }
1884 } else {
1885 if messages[m].Payload_RPC.HasValue(rpc.RPC_NEEDS_REPLYBACK_ADDRESS, rpc.DataString) {
1886 uname := ""
1887 for r := range result {
1888 if r > -1 && r < len(result) {
1889 if strings.Contains(result[r], messages[m].Destination+"~~~") {
1890 split := strings.Split(result[r], "~~~")
1891 uname = split[1]
1892 copy(result[r:], result[r+1:])

Callers 1

layoutMessagesFunction · 0.85

Calls 1

checkUsernameFunction · 0.85

Tested by

no test coverage detected