mirror of
https://github.com/vacp2p/research.git
synced 2025-02-23 19:58:30 +00:00
Whisper send and receive
This commit is contained in:
parent
925feb2d84
commit
bc925240f1
6
data_sync/private_client.py
Normal file
6
data_sync/private_client.py
Normal file
@ -0,0 +1,6 @@
|
||||
# What would a private messaging client look like?
|
||||
|
||||
# It should allow a node to send PRIVATE_MESSAGE
|
||||
|
||||
# Is this the most important thing to work on? Vs writing presentation for 30 people
|
||||
|
@ -1,6 +1,14 @@
|
||||
from web3 import shh
|
||||
from web3 import HTTPProvider, Web3
|
||||
from web3.personal import Personal
|
||||
import time
|
||||
|
||||
# Run geth repo with <OPTIONS>
|
||||
# Ensure there's a private key ~
|
||||
# Pubkey
|
||||
# 0x040cb9373bf8cd9dcbca4b75ccbfad52bbc66d1aaca8095adb2a7dcf8504146f0abde4ca22adf77b5062f113585befbf37e06dcadd0ce1093695e53d00d2109528
|
||||
|
||||
# XXX: Message not sent, due to threads?
|
||||
|
||||
status_host = 'http://127.0.0.1:8545'
|
||||
|
||||
@ -23,13 +31,20 @@ privkey = ms.getPrivateKey(id)
|
||||
print("privkey => ", privkey)
|
||||
|
||||
# XXX
|
||||
topic = Web3.toHex(b'AAAA')
|
||||
#topic = Web3.toHex(b'AAAA')
|
||||
topic = '0x00000000'
|
||||
print("topic => ", topic)
|
||||
text = 'test message'
|
||||
|
||||
# XXX
|
||||
address_to = '0x0487be55c072702a0e4da72158a7432281e8c26aca9501cd0bfeea726dc85f2611e96884e8fc4807c95c04c04af3387b83350a27cc18b96c37543e0f9a41ae47b5'
|
||||
#address_to = '0x0487be55c072702a0e4da72158a7432281e8c26aca9501cd0bfeea726dc85f2611e96884e8fc4807c95c04c04af3387b83350a27cc18b96c37543e0f9a41ae47b5'
|
||||
|
||||
# Copy pasted
|
||||
address_to = '0x04bbfb9fbe8239c2fb1895511f306d731c283ba3070d8642d4fbb4da1e4923454b8de6d82b671a4787c8e24d2cf2cf947d6da5ff6d12bf7147d1c0c5d2acbaf8ba'
|
||||
|
||||
# nice works
|
||||
|
||||
# address too is who?
|
||||
mes_send = ms.post(
|
||||
{
|
||||
'ttl': 20,
|
||||
@ -41,9 +56,5 @@ mes_send = ms.post(
|
||||
}
|
||||
)
|
||||
|
||||
if mes_send == True:
|
||||
print('Status message => Send')
|
||||
else:
|
||||
print('Message not send')
|
||||
|
||||
# TODO: Create a listener
|
||||
# How check status?
|
||||
print(mes_send)
|
||||
|
56
data_sync/whisper2.py
Normal file
56
data_sync/whisper2.py
Normal file
@ -0,0 +1,56 @@
|
||||
from web3 import Web3, HTTPProvider
|
||||
web3 = Web3(HTTPProvider('http://localhost:8545'))
|
||||
from web3.shh import Shh
|
||||
Shh.attach(web3, "shh")
|
||||
import time
|
||||
|
||||
# XXX: Seems broken
|
||||
raw_keyPair = web3.shh.newKeyPair()
|
||||
keyPair = "0x" + raw_keyPair
|
||||
|
||||
kId = web3.shh.addPrivateKey(keyPair)
|
||||
|
||||
topic = '0x00000000'
|
||||
|
||||
# TODO: Discovery topic or other one, or all
|
||||
myFilter = web3.shh.newMessageFilter({'topic': topic,
|
||||
'privateKeyID': kId})
|
||||
myFilter.poll_interval = 600;
|
||||
print('keyPair: ' + keyPair)
|
||||
print('Filter ID: ' + myFilter.filter_id)
|
||||
print(web3.shh.hasKeyPair(kId))
|
||||
print('PubKey: ' + web3.shh.getPublicKey(kId))
|
||||
|
||||
# Test messages
|
||||
|
||||
web3.shh.post({
|
||||
'pubKey': web3.shh.getPublicKey(kId),
|
||||
'topic': topic,
|
||||
'powTarget': 2.01,
|
||||
'powTime': 2,
|
||||
'ttl': 10,
|
||||
'payload': web3.toHex(text="test message :)")
|
||||
});
|
||||
|
||||
web3.shh.post({
|
||||
'pubKey': web3.shh.getPublicKey(kId),
|
||||
'topic': topic,
|
||||
'powTarget': 2.01,
|
||||
'powTime': 2,
|
||||
'ttl': 10,
|
||||
'payload': web3.toHex(text="test hello! :)")
|
||||
});
|
||||
|
||||
|
||||
# get and send message
|
||||
# should be same
|
||||
|
||||
def getMessages():
|
||||
filterID = myFilter.filter_id
|
||||
retreived_messages = web3.shh.getMessages(filterID)
|
||||
|
||||
for i in range(0, len(retreived_messages)):
|
||||
print(retreived_messages[i]['payload'].decode("utf-8"))
|
||||
print(retreived_messages[i])
|
||||
|
||||
# getMessages()
|
Loading…
x
Reference in New Issue
Block a user