Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DuniterPy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
DuniterPy
Commits
b216488e
Commit
b216488e
authored
Nov 18, 2016
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
Fix send documents
parent
642ec888
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/send_certification.py
+14
-19
14 additions, 19 deletions
examples/send_certification.py
examples/send_membership.py
+3
-8
3 additions, 8 deletions
examples/send_membership.py
examples/send_transaction.py
+16
-21
16 additions, 21 deletions
examples/send_transaction.py
with
33 additions
and
48 deletions
examples/send_certification.py
+
14
−
19
View file @
b216488e
...
@@ -13,17 +13,6 @@ from duniterpy.key import SigningKey
...
@@ -13,17 +13,6 @@ from duniterpy.key import SigningKey
# Here we use the BASIC_MERKLED_API
# Here we use the BASIC_MERKLED_API
BMA_ENDPOINT
=
"
BASIC_MERKLED_API cgeek.fr 9330
"
BMA_ENDPOINT
=
"
BASIC_MERKLED_API cgeek.fr 9330
"
# Public key of the certifier
FROM_PUBKEY
=
"
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
"
# Credentials should be prompted or kept in a separate secure file
# create a file with the salt on the first line and the password on the second line
# the script will load them from the file
FROM_CREDENTIALS_FILE
=
"
/home/username/.credentials.txt
"
# Public key to certified
TO_PUBKEY
=
"
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
"
################################################
################################################
# Latest duniter-python-api is asynchronous and you have to create an aiohttp session to send request
# Latest duniter-python-api is asynchronous and you have to create an aiohttp session to send request
...
@@ -103,25 +92,31 @@ async def main():
...
@@ -103,25 +92,31 @@ async def main():
# connection handler from BMA endpoint
# connection handler from BMA endpoint
connection
=
BMAEndpoint
.
from_inline
(
BMA_ENDPOINT
).
conn_handler
(
AIOHTTP_SESSION
)
connection
=
BMAEndpoint
.
from_inline
(
BMA_ENDPOINT
).
conn_handler
(
AIOHTTP_SESSION
)
# capture current block to get version and currency and blockstamp
current_block
=
await
bma
.
blockchain
.
current
(
connection
)
# create our SelfCertification document to sign the Certification document
identity
=
await
get_identity_document
(
connection
,
current_block
,
TO_PUBKEY
)
# prompt hidden user entry
# prompt hidden user entry
salt
=
getpass
.
getpass
(
"
Enter your passphrase (salt):
"
)
salt
=
getpass
.
getpass
(
"
Enter your passphrase (salt):
"
)
# prompt hidden user entry
# prompt hidden user entry
password
=
getpass
.
getpass
(
"
Enter your password :
"
)
password
=
getpass
.
getpass
(
"
Enter your password :
"
)
# prompt hidden user entry
pubkey_from
=
getpass
.
getpass
(
"
Enter your pubkey :
"
)
# prompt hidden user entry
pubkey_to
=
getpass
.
getpass
(
"
Enter certified pubkey :
"
)
# capture current block to get version and currency and blockstamp
current_block
=
await
bma
.
blockchain
.
current
(
connection
)
# create our SelfCertification document to sign the Certification document
identity
=
await
get_identity_document
(
connection
,
current_block
,
pubkey_to
)
# send the Certification document to the node
# send the Certification document to the node
certification
=
get_certification_document
(
current_block
,
identity
,
FROM_PUBKEY
,
salt
,
password
)
certification
=
get_certification_document
(
current_block
,
identity
,
pubkey_from
,
salt
,
password
)
# Here we request for the path wot/certify
# Here we request for the path wot/certify
response
=
await
bma
.
wot
.
certify
(
connection
,
certification
.
signed_raw
(
identity
))
response
=
await
bma
.
wot
.
certify
(
connection
,
certification
.
signed_raw
(
identity
))
if
response
.
status
_code
==
200
:
if
response
.
status
==
200
:
print
(
await
response
.
text
())
print
(
await
response
.
text
())
else
:
else
:
print
(
"
Error while publishing certification : {0}
"
.
format
(
response
.
text
()))
print
(
"
Error while publishing certification : {0}
"
.
format
(
response
.
text
()))
...
...
This diff is collapsed.
Click to expand it.
examples/send_membership.py
+
3
−
8
View file @
b216488e
...
@@ -14,14 +14,6 @@ from duniterpy.key import SigningKey
...
@@ -14,14 +14,6 @@ from duniterpy.key import SigningKey
# Here we use the BASIC_MERKLED_API
# Here we use the BASIC_MERKLED_API
BMA_ENDPOINT
=
"
BASIC_MERKLED_API cgeek.fr 9330
"
BMA_ENDPOINT
=
"
BASIC_MERKLED_API cgeek.fr 9330
"
# Credentials should be prompted or kept in a separate secure file
# create a file with the salt on the first line and the password on the second line
# the script will load them from the file
FROM_CREDENTIALS_FILE
=
"
/home/username/.credentials.txt
"
# Your unique identifier in the Web of Trust
UID
=
"
MyIdentity
"
################################################
################################################
# Latest duniter-python-api is asynchronous and you have to create an aiohttp session to send request
# Latest duniter-python-api is asynchronous and you have to create an aiohttp session to send request
...
@@ -115,6 +107,9 @@ async def main():
...
@@ -115,6 +107,9 @@ async def main():
# prompt hidden user entry
# prompt hidden user entry
password
=
getpass
.
getpass
(
"
Enter your password:
"
)
password
=
getpass
.
getpass
(
"
Enter your password:
"
)
# prompt hidden user entry
UID
=
getpass
.
getpass
(
"
Enter your UID:
"
)
# create our signed identity document
# create our signed identity document
identity
=
get_identity_document
(
current_block
,
UID
,
salt
,
password
)
identity
=
get_identity_document
(
current_block
,
UID
,
salt
,
password
)
...
...
This diff is collapsed.
Click to expand it.
examples/send_transaction.py
+
16
−
21
View file @
b216488e
...
@@ -15,17 +15,6 @@ from duniterpy.key import SigningKey
...
@@ -15,17 +15,6 @@ from duniterpy.key import SigningKey
# Here we use the BASIC_MERKLED_API
# Here we use the BASIC_MERKLED_API
BMA_ENDPOINT
=
"
BASIC_MERKLED_API cgeek.fr 9330
"
BMA_ENDPOINT
=
"
BASIC_MERKLED_API cgeek.fr 9330
"
# Credentials should be prompted or kept in a separate secure file
# create a file with the salt on the first line and the password on the second line
# the script will load them from the file
FROM_CREDENTIALS_FILE
=
"
/home/username/.credentials.txt
"
# Public key of the source account
FROM_PUBKEY
=
"
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
"
# Public key of the target account
TO_PUBKEY
=
"
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
"
################################################
################################################
...
@@ -107,27 +96,33 @@ async def main():
...
@@ -107,27 +96,33 @@ async def main():
# connection handler from BMA endpoint
# connection handler from BMA endpoint
connection
=
BMAEndpoint
.
from_inline
(
BMA_ENDPOINT
).
conn_handler
(
AIOHTTP_SESSION
)
connection
=
BMAEndpoint
.
from_inline
(
BMA_ENDPOINT
).
conn_handler
(
AIOHTTP_SESSION
)
# prompt hidden user entry
salt
=
getpass
.
getpass
(
"
Enter your passphrase (salt):
"
)
# prompt hidden user entry
password
=
getpass
.
getpass
(
"
Enter your password :
"
)
# prompt hidden user entry
pubkey_from
=
getpass
.
getpass
(
"
Enter your pubkey :
"
)
# prompt hidden user entry
pubkey_to
=
getpass
.
getpass
(
"
Enter recipient pubkey :
"
)
# capture current block to get version and currency and blockstamp
# capture current block to get version and currency and blockstamp
current_block
=
await
bma
.
blockchain
.
current
(
connection
)
current_block
=
await
bma
.
blockchain
.
current
(
connection
)
# capture sources of account
# capture sources of account
response
=
await
bma
.
tx
.
sources
(
connection
,
FROM_PUBKEY
)
response
=
await
bma
.
tx
.
sources
(
connection
,
pubkey_from
)
if
len
(
response
[
'
sources
'
])
==
0
:
if
len
(
response
[
'
sources
'
])
==
0
:
print
(
"
no sources found for account %s
"
%
FROM_PUBKEY
)
print
(
"
no sources found for account %s
"
%
pubkey_to
)
exit
(
1
)
exit
(
1
)
# get the first source
# get the first source
source
=
response
[
'
sources
'
][
0
]
source
=
response
[
'
sources
'
][
0
]
# create the transaction document
# create the transaction document
transaction
=
get_transaction_document
(
current_block
,
source
,
FROM_PUBKEY
,
TO_PUBKEY
)
transaction
=
get_transaction_document
(
current_block
,
source
,
pubkey_from
,
pubkey_to
)
# load credentials from a text file
salt
,
password
=
open
(
FROM_CREDENTIALS_FILE
).
readlines
()
# cleanup newlines
salt
,
password
=
salt
.
strip
(),
password
.
strip
()
# create keys from credentials
# create keys from credentials
key
=
SigningKey
(
salt
,
password
)
key
=
SigningKey
(
salt
,
password
)
...
@@ -141,7 +136,7 @@ async def main():
...
@@ -141,7 +136,7 @@ async def main():
if
response
.
status
==
200
:
if
response
.
status
==
200
:
print
(
await
response
.
text
())
print
(
await
response
.
text
())
else
:
else
:
print
(
"
Error while publishing transaction : {0}
"
.
format
(
response
.
text
()))
print
(
"
Error while publishing transaction : {0}
"
.
format
(
await
response
.
text
()))
response
.
close
()
response
.
close
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment