hive-nectar 0.0.11__py3-none-any.whl → 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of hive-nectar might be problematic. Click here for more details.

Files changed (56) hide show
  1. {hive_nectar-0.0.11.dist-info → hive_nectar-0.1.0.dist-info}/METADATA +10 -11
  2. hive_nectar-0.1.0.dist-info/RECORD +88 -0
  3. nectar/__init__.py +1 -4
  4. nectar/account.py +791 -685
  5. nectar/amount.py +82 -21
  6. nectar/asset.py +1 -2
  7. nectar/block.py +34 -22
  8. nectar/blockchain.py +111 -143
  9. nectar/blockchaininstance.py +396 -247
  10. nectar/blockchainobject.py +33 -5
  11. nectar/cli.py +1058 -1349
  12. nectar/comment.py +313 -181
  13. nectar/community.py +39 -43
  14. nectar/constants.py +1 -14
  15. nectar/discussions.py +793 -139
  16. nectar/hive.py +137 -77
  17. nectar/hivesigner.py +106 -68
  18. nectar/imageuploader.py +33 -23
  19. nectar/instance.py +31 -79
  20. nectar/market.py +128 -264
  21. nectar/memo.py +40 -13
  22. nectar/message.py +23 -10
  23. nectar/nodelist.py +115 -81
  24. nectar/price.py +80 -61
  25. nectar/profile.py +6 -3
  26. nectar/rc.py +45 -25
  27. nectar/snapshot.py +285 -163
  28. nectar/storage.py +16 -5
  29. nectar/transactionbuilder.py +132 -41
  30. nectar/utils.py +37 -17
  31. nectar/version.py +1 -1
  32. nectar/vote.py +171 -30
  33. nectar/wallet.py +26 -19
  34. nectar/witness.py +153 -54
  35. nectarapi/graphenerpc.py +147 -133
  36. nectarapi/noderpc.py +12 -6
  37. nectarapi/rpcutils.py +12 -6
  38. nectarapi/version.py +1 -1
  39. nectarbase/ledgertransactions.py +24 -1
  40. nectarbase/objects.py +17 -6
  41. nectarbase/operations.py +160 -90
  42. nectarbase/signedtransactions.py +38 -2
  43. nectarbase/version.py +1 -1
  44. nectargraphenebase/account.py +295 -17
  45. nectargraphenebase/chains.py +0 -135
  46. nectargraphenebase/ecdsasig.py +152 -176
  47. nectargraphenebase/types.py +18 -4
  48. nectargraphenebase/unsignedtransactions.py +1 -1
  49. nectargraphenebase/version.py +1 -1
  50. hive_nectar-0.0.11.dist-info/RECORD +0 -91
  51. nectar/blurt.py +0 -562
  52. nectar/conveyor.py +0 -308
  53. nectar/steem.py +0 -581
  54. {hive_nectar-0.0.11.dist-info → hive_nectar-0.1.0.dist-info}/WHEEL +0 -0
  55. {hive_nectar-0.0.11.dist-info → hive_nectar-0.1.0.dist-info}/entry_points.txt +0 -0
  56. {hive_nectar-0.0.11.dist-info → hive_nectar-0.1.0.dist-info}/licenses/LICENSE.txt +0 -0
nectar/imageuploader.py CHANGED
@@ -5,6 +5,7 @@ from binascii import hexlify
5
5
  import requests
6
6
 
7
7
  from nectar.account import Account
8
+ from nectar.exceptions import MissingKeyError
8
9
  from nectargraphenebase.ecdsasig import sign_message
9
10
 
10
11
  from .instance import shared_blockchain_instance
@@ -13,46 +14,55 @@ from .instance import shared_blockchain_instance
13
14
  class ImageUploader(object):
14
15
  def __init__(
15
16
  self,
16
- base_url="https://steemitimages.com",
17
+ base_url="https://images.hive.blog",
17
18
  challenge="ImageSigningChallenge",
18
19
  blockchain_instance=None,
19
- **kwargs,
20
20
  ):
21
+ """
22
+ Initialize the ImageUploader.
23
+
24
+ Parameters:
25
+ base_url (str): Base URL of the image upload service (default: "https://images.hive.blog").
26
+ challenge (str): ASCII string prepended to the image bytes when constructing the signing message; ensures signatures are bound to this uploader's purpose.
27
+
28
+ Notes:
29
+ blockchain_instance is an optional blockchain client; if not provided a shared instance is used.
30
+ """
21
31
  self.challenge = challenge
22
32
  self.base_url = base_url
23
- if blockchain_instance is None:
24
- if kwargs.get("steem_instance"):
25
- blockchain_instance = kwargs["steem_instance"]
26
- elif kwargs.get("hive_instance"):
27
- blockchain_instance = kwargs["hive_instance"]
28
- self.steem = blockchain_instance or shared_blockchain_instance()
29
- if self.steem.is_hive and base_url == "https://steemitimages.com":
30
- self.base_url = "https://images.hive.blog"
33
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
31
34
 
32
35
  def upload(self, image, account, image_name=None):
33
- """Uploads an image
36
+ """
37
+ Upload an image to the configured image service, signing the upload with the account's posting key.
34
38
 
35
- :param image: path to the image or image in bytes representation which should be uploaded
36
- :type image: str, bytes
37
- :param str account: Account which is used to upload. A posting key must be provided.
38
- :param str image_name: optional
39
+ The function accepts a filesystem path (str), raw bytes, or an io.BytesIO for the image. It locates the account's posting private key from the blockchain wallet, signs the image data together with the uploader's challenge string, and POSTs the image under the key `image_name` (defaults to "image") to: <base_url>/<account_name>/<signature_hex>.
39
40
 
40
- .. code-block:: python
41
+ Parameters:
42
+ image (str | bytes | io.BytesIO): Path to an image file, raw image bytes, or an in-memory bytes buffer.
43
+ account (str | Account): Account identifier (must have posting permission); used to select the signing key.
44
+ image_name (str, optional): Form field name for the uploaded image (defaults to "image").
41
45
 
42
- from nectar import Steem
43
- from nectar.imageuploader import ImageUploader
44
- stm = Steem(keys=["5xxx"]) # private posting key
45
- iu = ImageUploader(blockchain_instance=stm)
46
- iu.upload("path/to/image.png", "account_name") # "private posting key belongs to account_name
46
+ Returns:
47
+ dict: Parsed JSON response from the image service.
47
48
 
49
+ Raises:
50
+ AssertionError: If the account's posting permission (and therefore a posting key) cannot be accessed.
48
51
  """
49
- account = Account(account, blockchain_instance=self.steem)
52
+ account = Account(account, blockchain_instance=self.blockchain)
50
53
  if "posting" not in account:
51
54
  account.refresh()
52
55
  if "posting" not in account:
53
56
  raise AssertionError("Could not access posting permission")
57
+ posting_wif = None
54
58
  for authority in account["posting"]["key_auths"]:
55
- posting_wif = self.steem.wallet.getPrivateKeyForPublicKey(authority[0])
59
+ try:
60
+ posting_wif = self.blockchain.wallet.getPrivateKeyForPublicKey(authority[0])
61
+ break
62
+ except MissingKeyError:
63
+ continue
64
+ if not posting_wif:
65
+ raise AssertionError("No local private posting key available to sign the image.")
56
66
 
57
67
  if isinstance(image, str):
58
68
  image_data = open(image, "rb").read()
nectar/instance.py CHANGED
@@ -3,122 +3,74 @@ import nectar
3
3
 
4
4
 
5
5
  class SharedInstance(object):
6
- """Singelton for the Steem Instance"""
6
+ """Singleton for the shared Blockchain Instance (Hive-only)."""
7
7
 
8
8
  instance = None
9
9
  config = {}
10
10
 
11
11
 
12
12
  def shared_blockchain_instance():
13
- """This method will initialize ``SharedInstance.instance`` and return it.
14
- The purpose of this method is to have offer single default
15
- steem instance that can be reused by multiple classes.
16
-
17
- .. code-block:: python
18
-
19
- from nectar.account import Account
20
- from nectar.instance import shared_steem_instance
21
-
22
- account = Account("test")
23
- # is equivalent with
24
- account = Account("test", blockchain_instance=shared_steem_instance())
13
+ """Initialize and return the shared Hive instance.
25
14
 
15
+ Hive-only: this always returns a `nectar.Hive` instance, regardless of any
16
+ legacy configuration that may have referenced other chains.
26
17
  """
27
18
  if not SharedInstance.instance:
28
19
  clear_cache()
29
- from nectar.storage import get_default_config_store
30
-
31
- default_chain = get_default_config_store()["default_chain"]
32
- if default_chain == "steem":
33
- SharedInstance.instance = nectar.Steem(**SharedInstance.config)
34
- else:
35
- SharedInstance.instance = nectar.Hive(**SharedInstance.config)
20
+ SharedInstance.instance = nectar.Hive(**SharedInstance.config)
36
21
  return SharedInstance.instance
37
22
 
38
23
 
39
24
  def set_shared_blockchain_instance(blockchain_instance):
40
- """This method allows us to override default steem instance for all users of
41
- ``SharedInstance.instance``.
25
+ """
26
+ Override the shared Hive instance used by the module and clear related caches.
42
27
 
43
- :param Steem blockchain_instance: Steem instance
28
+ This sets SharedInstance.instance to the provided blockchain instance and calls clear_cache()
29
+ to invalidate any cached blockchain objects so consumers observe the new instance immediately.
44
30
  """
45
31
  clear_cache()
46
32
  SharedInstance.instance = blockchain_instance
47
33
 
48
34
 
49
- def shared_steem_instance():
50
- """This method will initialize ``SharedInstance.instance`` and return it.
51
- The purpose of this method is to have offer single default
52
- steem instance that can be reused by multiple classes.
53
-
54
- .. code-block:: python
55
-
56
- from nectar.account import Account
57
- from nectar.instance import shared_steem_instance
35
+ def shared_hive_instance():
36
+ """Initialize (if needed) and return the shared Hive instance."""
37
+ return shared_blockchain_instance()
58
38
 
59
- account = Account("test")
60
- # is equivalent with
61
- account = Account("test", blockchain_instance=shared_steem_instance())
62
39
 
40
+ def set_shared_hive_instance(hive_instance):
63
41
  """
64
- if not SharedInstance.instance:
65
- clear_cache()
66
- SharedInstance.instance = nectar.Steem(**SharedInstance.config)
67
- return SharedInstance.instance
68
-
42
+ Override the global shared Hive instance used by the module.
69
43
 
70
- def set_shared_steem_instance(steem_instance):
71
- """This method allows us to override default steem instance for all users of
72
- ``SharedInstance.instance``.
44
+ Replaces the current SharedInstance.instance with the provided hive_instance and clears related caches so subsequent calls return the new instance.
73
45
 
74
- :param Steem steem_instance: Steem instance
46
+ Parameters:
47
+ hive_instance: The nectar.Hive instance to set as the shared global instance.
75
48
  """
76
- clear_cache()
77
- SharedInstance.instance = steem_instance
78
-
79
-
80
- def shared_hive_instance():
81
- """This method will initialize ``SharedInstance.instance`` and return it.
82
- The purpose of this method is to have offer single default
83
- steem instance that can be reused by multiple classes.
49
+ set_shared_blockchain_instance(hive_instance)
84
50
 
85
- .. code-block:: python
86
-
87
- from nectar.account import Account
88
- from nectar.instance import shared_hive_instance
89
-
90
- account = Account("test")
91
- # is equivalent with
92
- account = Account("test", blockchain_instance=shared_hive_instance())
93
51
 
52
+ def clear_cache():
94
53
  """
95
- if not SharedInstance.instance:
96
- clear_cache()
97
- SharedInstance.instance = nectar.Hive(**SharedInstance.config)
98
- return SharedInstance.instance
99
-
100
-
101
- def set_shared_hive_instance(hive_instance):
102
- """This method allows us to override default steem instance for all users of
103
- ``SharedInstance.instance``.
54
+ Clear cached blockchain object state.
104
55
 
105
- :param Hive hive_instance: Hive instance
56
+ Performs a lazy import of BlockchainObject and calls its clear_cache() method to purge any in-memory caches of blockchain objects (used when the shared Hive instance or configuration changes).
106
57
  """
107
- clear_cache()
108
- SharedInstance.instance = hive_instance
109
-
110
-
111
- def clear_cache():
112
- """Clear Caches"""
113
58
  from .blockchainobject import BlockchainObject
114
59
 
115
60
  BlockchainObject.clear_cache()
116
61
 
117
62
 
118
63
  def set_shared_config(config):
119
- """This allows to set a config that will be used when calling
120
- ``shared_steem_instance`` and allows to define the configuration
121
- without requiring to actually create an instance
64
+ """
65
+ Set configuration for the shared Hive instance without creating the instance.
66
+
67
+ Updates the global SharedInstance.config with the provided mapping. If a shared instance already exists, clears internal caches and resets the shared instance to None so the new configuration will take effect on next access.
68
+
69
+ Parameters:
70
+ config (dict): Configuration options to merge into the shared instance configuration.
71
+
72
+ Raises:
73
+ AssertionError: If `config` is not a dict.
122
74
  """
123
75
  if not isinstance(config, dict):
124
76
  raise AssertionError()