Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycfhelpers
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cellframe
python-cellframe-modules
pycfhelpers
Commits
41484067
Commit
41484067
authored
1 year ago
by
boo
Browse files
Options
Downloads
Patches
Plain Diff
add items and ledger
parent
8f2ea5cc
Loading
Loading
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
cellframenet.py
+7
-0
7 additions, 0 deletions
cellframenet.py
cfnet_struct.py
+96
-35
96 additions, 35 deletions
cfnet_struct.py
mappings.py
+69
-0
69 additions, 0 deletions
mappings.py
types.py
+0
-33
0 additions, 33 deletions
types.py
with
172 additions
and
68 deletions
cellframenet.py
+
7
−
0
View file @
41484067
...
...
@@ -190,11 +190,16 @@ class CellframeNetwork:
logIt
.
notice
(
"
New mempool notifier for {}
"
.
format
(
callback_name
))
def
callback_wraper
(
op_code
,
group
,
key
,
value
,
net_name
):
# op_code a | d
# group - table name
# key - hash записи
#
callback
(
op_code
,
group
,
key
,
value
,
net_name
,
self
,
chain
)
chain
.
addMempoolNotify
(
callback_wraper
,
callback_name
)
def
set_gdbsync_notification_callback
(
self
,
callback
):
# Любая таблица в GDB
callback_name
=
"
{}
"
.
format
(
self
.
name
)
logIt
.
notice
(
"
New gdb notifier for {}
"
.
format
(
callback_name
))
...
...
@@ -205,6 +210,8 @@ class CellframeNetwork:
self
.
net
.
addNotify
(
callback_wraper
,
self
.
name
)
def
set_atom_notification_callback
(
self
,
chain
,
callback
):
# New atom Block | Event
#
callback_name
=
"
{}
"
.
format
(
self
.
name
)
logIt
.
notice
(
"
New atom notifier for {}
"
.
format
(
callback_name
))
...
...
This diff is collapsed.
Click to expand it.
cfnet_struct.py
+
96
−
35
View file @
41484067
from
__future__
import
annotations
from
typing
import
Iterator
from
typing
import
Iterator
,
NewType
from
datetime
import
datetime
from
abc
import
ABC
,
abstractmethod
,
abstractproperty
from
abc
import
ABC
,
abstractmethod
from
CellFrame.Chain
import
ChainAtomPtr
,
ChainAddr
,
Mempool
,
Wallet
,
Chain
,
Ledger
from
CellFrame.Common
import
Datum
,
DatumTx
,
DatumToken
,
DatumEmission
,
DatumAnchor
,
DatumDecree
from
CellFrame.Chain
import
ChainAtomPtr
,
ChainAddr
,
Mempool
,
Wallet
,
Chain
from
CellFrame.Common
import
Datum
,
DatumIter
,
DatumTx
,
DatumToken
,
DatumEmission
,
DatumAnchor
,
DatumDecree
from
CellFrame.Consensus
import
DAG
,
Block
from
CellFrame.Network
import
Net
from
CellFrame.Common
import
TxIn
,
TxInCond
,
TxOut
,
TxOutCond
,
TxPkey
,
TxSig
,
TxToken
,
TxReceipt
,
TxOutExt
,
TxTSD
from
DAP.Crypto
import
HashFast
,
Sign
,
Pkey
from
DAP.Core
import
logIt
from
pycfhelpers
.types
import
ChainTypes
,
Datu
mTypes
from
shared
.types
import
DatumTypes
,
ChainTypes
,
Ite
mTypes
# from .mappings import CFSubDatumBuilder, CFItemMapper
class
MixinToDictWithSlots
:
def
to_dict
(
self
):
keys
=
self
.
__slots__
values
=
[
getattr
(
self
,
key
)
for
key
in
keys
]
return
dict
(
zip
(
keys
,
values
))
OriginItemTypes
=
TxIn
|
TxInCond
|
TxOut
|
TxOutCond
|
TxPkey
|
TxSig
|
TxToken
|
TxReceipt
|
TxOutExt
|
TxTSD
ticker
=
NewType
(
"
ticker
"
,
str
)
class
CFNet
:
...
...
@@ -41,6 +41,9 @@ class CFNet:
def
chains
(
self
)
->
list
[
'
CFChain
'
]:
return
[
self
.
main
,
self
.
zerochain
]
def
get_ledger
(
self
):
return
CFLedger
(
self
,
self
.
_origin_net
.
getLedger
())
class
CFChain
:
def
__init__
(
self
,
net
:
CFNet
,
chain_name
:
str
):
...
...
@@ -85,6 +88,15 @@ class CFChain:
yield
datum
.
_origin_datum
.
getDatumTX
()
class
CFLedger
:
def
__init__
(
self
,
net
:
CFNet
,
ledger
:
Ledger
=
None
):
self
.
net
=
net
self
.
_origin_ledger
=
ledger
or
self
.
net
.
get_ledger
()
def
get_ticker
(
self
,
datum
:
CFDatumTX
)
->
ticker
|
None
:
return
self
.
_origin_ledger
.
txGetTokenTickerByHash
(
HashFast
.
fromString
(
datum
.
hash
))
class
CFBlock
:
def
__init__
(
self
,
atom
:
ChainAtomPtr
,
chain
:
CFChain
):
self
.
_origin_atom
=
atom
...
...
@@ -142,35 +154,17 @@ class CFDatum:
self
.
hash
=
str
(
datum
.
hash
)
self
.
atom
=
atom
def
_get_origin_sub_datum
(
self
)
->
DatumTx
|
DatumToken
|
DatumEmission
|
DatumAnchor
|
bytes
:
sub_datums
=
{
"
DATUM_TX
"
:
self
.
_origin_datum
.
getDatumTX
,
"
DATUM_TOKEN_DECL
"
:
self
.
_origin_datum
.
getDatumToken
,
"
DATUM_TOKEN_EMISSION
"
:
self
.
_origin_datum
.
getDatumTokenEmission
,
"
DATUM_DECREE
"
:
self
.
_origin_datum
.
getDatumDecree
,
"
DATUM_ANCHOR
"
:
self
.
_origin_datum
.
getDatumAnchor
,
"
DATUM_CUSTOM
"
:
self
.
_origin_datum
.
dataRaw
,
}
return
sub_datums
[
self
.
type
]()
def
get_sub_datum
(
self
)
->
CFDatumTX
|
CFDatumToken
|
CFDatumEmission
|
CFDatumAnchor
|
CFDatumDecree
|
CFDatumCustom
:
sub_datum_wrappers
=
{
"
DATUM_TX
"
:
CFDatumTX
,
"
DATUM_TOKEN_DECL
"
:
CFDatumToken
,
"
DATUM_TOKEN_EMISSION
"
:
CFDatumEmission
,
"
DATUM_DECREE
"
:
CFDatumDecree
,
"
DATUM_ANCHOR
"
:
CFDatumAnchor
,
"
DATUM_CUSTOM
"
:
CFDatumCustom
,
}
return
sub_datum_wrappers
[
self
.
type
](
self
,
self
.
_get_origin_sub_datum
())
def
get_sub_datum
(
self
)
->
CFDatumTX
|
CFDatumToken
|
CFDatumEmission
|
CFDatumAnchor
|
CFDatumDecree
|
CFDatumCustom
:
# FIXME: change struct
from
.mappings
import
CFSubDatumBuilder
return
CFSubDatumBuilder
(
self
.
type
).
build
(
self
)
class
SubDatum
:
def
__init__
(
self
,
parent_datum
:
CFDatum
,
sub_datum
):
self
.
_parent_datum
=
parent_datum
self
.
_origin_sub_datum
=
sub_datum
self
.
bad
=
False
@property
def
net
(
self
)
->
CFNet
:
...
...
@@ -184,6 +178,75 @@ class CFDatumTX(SubDatum):
super
().
__init__
(
parent_datum
,
sub_datum
)
self
.
hash
=
str
(
sub_datum
.
hash
)
self
.
created_at
=
sub_datum
.
dateCreated
ledger
=
self
.
net
.
get_ledger
()
self
.
ticker
=
ledger
.
get_ticker
(
self
)
def
get_items
(
self
)
->
list
[
CFItem
]:
# FIXME: change struct
from
.mappings
import
CFItemMapper
return
[
CFItemMapper
.
build
(
item
)
for
item
in
self
.
_origin_sub_datum
.
getItems
()
if
item
is
not
None
]
class
CFItem
:
def
__init__
(
self
,
origin_item
:
OriginItemTypes
,
type
:
ItemTypes
):
self
.
_origin_item
=
origin_item
self
.
type
=
type
class
CFTxIn
(
CFItem
):
pass
class
CFTxInCond
(
CFItem
):
pass
class
CFTxOut
(
CFItem
):
pass
class
CFTxOutCond
(
CFItem
):
pass
class
CFTxPkey
(
CFItem
):
pass
class
CFTxSig
(
CFItem
):
pass
class
CFTxToken
(
CFItem
):
pass
class
CFTxReceipt
(
CFItem
):
pass
class
CFTxOutExt
(
CFItem
):
pass
class
CFTxTSD
(
CFItem
):
pass
class
CFTxOutCondSubtypeSrvPay
(
CFItem
):
pass
class
CFTxOutCondSubtypeSrvXchange
(
CFItem
):
pass
class
CFTxOutCondSubtypeSrvStakeLock
(
CFItem
):
pass
class
CFTxOutCondSubtypeSrvStakePosDelegate
(
CFItem
):
pass
class
CFDatumToken
(
SubDatum
):
...
...
@@ -198,8 +261,6 @@ class CFDatumToken(SubDatum):
self
.
signs
=
[
CFSign
(
sign
,
self
.
net
)
for
sign
in
sub_datum
.
signs
]
except
AttributeError
as
e
:
self
.
signs
=
[]
# Problematic datum
self
.
bad
=
True
logIt
.
message
(
f
"
{
self
.
_parent_datum
.
type
=
}
"
)
logIt
.
message
(
f
"
{
self
.
_parent_datum
.
hash
=
}
"
)
logIt
.
message
(
f
"
{
self
.
type
=
}
"
)
...
...
This diff is collapsed.
Click to expand it.
mappings.py
0 → 100644
+
69
−
0
View file @
41484067
from
collections
import
namedtuple
from
CellFrame.Common
import
(
TxIn
,
TxInCond
,
TxOut
,
TxOutCond
,
TxPkey
,
TxSig
,
TxToken
,
TxReceipt
,
TxOutExt
,
TxTSD
,
TxOutCondSubtypeSrvPay
,
TxOutCondSubtypeSrvXchange
,
TxOutCondSubtypeSrvStakeLock
,
TxOutCondSubtypeSrvStakePosDelegate
)
from
CellFrame.Common
import
Datum
from
logger
import
logIt
from
shared.types
import
ItemTypes
,
DatumTypes
from
.cfnet_struct
import
(
CFTxIn
,
CFTxInCond
,
CFTxOut
,
CFTxOutCond
,
CFTxPkey
,
CFTxSig
,
CFTxToken
,
CFTxReceipt
,
CFTxOutExt
,
CFTxTSD
,
CFTxOutCondSubtypeSrvPay
,
CFTxOutCondSubtypeSrvXchange
,
CFTxOutCondSubtypeSrvStakeLock
,
CFTxOutCondSubtypeSrvStakePosDelegate
)
from
.cfnet_struct
import
CFDatumTX
,
CFDatumToken
,
CFDatumEmission
,
CFDatumCustom
,
CFDatumDecree
,
CFDatumAnchor
CFItemTypes
=
CFTxIn
|
CFTxInCond
|
CFTxOut
|
CFTxOutCond
|
CFTxPkey
|
CFTxSig
|
CFTxToken
|
CFTxReceipt
|
CFTxOutExt
|
CFTxTSD
ItemMeta
=
namedtuple
(
'
ItemMapping
'
,
[
'
cf_wrapper_cls
'
,
'
type
'
])
ITEM_WRAPPER_MAPPING
=
{
TxIn
:
ItemMeta
(
CFTxIn
,
ItemTypes
.
TX_ITEM_TYPE_IN
),
TxInCond
:
ItemMeta
(
CFTxInCond
,
ItemTypes
.
TX_ITEM_TYPE_IN_COND
),
TxOut
:
ItemMeta
(
CFTxOut
,
ItemTypes
.
TX_ITEM_TYPE_OUT
),
TxOutCond
:
ItemMeta
(
CFTxOutCond
,
ItemTypes
.
TX_ITEM_TYPE_OUT_COND
),
TxPkey
:
ItemMeta
(
CFTxPkey
,
ItemTypes
.
TX_ITEM_TYPE_PKEY
),
TxSig
:
ItemMeta
(
CFTxSig
,
ItemTypes
.
TX_ITEM_TYPE_SIG
),
TxToken
:
ItemMeta
(
CFTxToken
,
ItemTypes
.
TX_ITEM_TYPE_IN_EMS
),
TxReceipt
:
ItemMeta
(
CFTxReceipt
,
ItemTypes
.
TX_ITEM_TYPE_RECEIPT
),
TxOutExt
:
ItemMeta
(
CFTxOutExt
,
ItemTypes
.
TX_ITEM_TYPE_OUT_EXT
),
TxTSD
:
ItemMeta
(
CFTxTSD
,
ItemTypes
.
TX_ITEM_TYPE_TSD
),
TxOutCondSubtypeSrvPay
:
ItemMeta
(
CFTxOutCondSubtypeSrvPay
,
ItemTypes
.
DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_PAY
),
TxOutCondSubtypeSrvXchange
:
ItemMeta
(
CFTxOutCondSubtypeSrvXchange
,
ItemTypes
.
DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_XCHANGE
),
TxOutCondSubtypeSrvStakeLock
:
ItemMeta
(
CFTxOutCondSubtypeSrvStakeLock
,
ItemTypes
.
DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_STAKE_LOCK
),
TxOutCondSubtypeSrvStakePosDelegate
:
ItemMeta
(
CFTxOutCondSubtypeSrvStakePosDelegate
,
ItemTypes
.
DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_STAKE_POS_DELEGATE
),
}
class
CFItemMapper
:
@staticmethod
def
build
(
origin_item
)
->
CFItemTypes
:
logIt
.
message
(
f
"
{
type
(
origin_item
)
=
}
"
)
mapping
=
ITEM_WRAPPER_MAPPING
.
get
(
type
(
origin_item
))
return
mapping
.
cf_wrapper_cls
(
origin_item
,
mapping
.
type
)
SubDatumMeta
=
namedtuple
(
'
SubDatumMapping
'
,
[
'
origin_method_name
'
,
'
cf_wrapper_cls
'
])
SUB_DATUM_WRAPPER_MAPPING
=
{
DatumTypes
.
DATUM_TX
:
SubDatumMeta
(
"
getDatumTX
"
,
CFDatumTX
),
DatumTypes
.
DATUM_TOKEN_DECL
:
SubDatumMeta
(
"
getDatumToken
"
,
CFDatumToken
),
DatumTypes
.
DATUM_TOKEN_EMISSION
:
SubDatumMeta
(
"
getDatumTokenEmission
"
,
CFDatumEmission
),
DatumTypes
.
DATUM_CUSTOM
:
SubDatumMeta
(
"
getDatumCustom
"
,
CFDatumCustom
),
DatumTypes
.
DATUM_DECREE
:
SubDatumMeta
(
"
getDatumDecree
"
,
CFDatumDecree
),
DatumTypes
.
DATUM_ANCHOR
:
SubDatumMeta
(
"
getDatumAnchor
"
,
CFDatumAnchor
),
}
class
CFSubDatumBuilder
:
def
__init__
(
self
,
type
:
DatumTypes
):
self
.
type
=
type
def
build
(
self
,
parent_datum
):
method
=
getattr
(
parent_datum
.
_origin_datum
,
SUB_DATUM_WRAPPER_MAPPING
[
self
.
type
].
origin_method_name
)
sub_datum
=
method
()
return
SUB_DATUM_WRAPPER_MAPPING
[
self
.
type
].
cf_wrapper_cls
(
parent_datum
,
sub_datum
)
This diff is collapsed.
Click to expand it.
types.py
deleted
100644 → 0
+
0
−
33
View file @
8f2ea5cc
from
enum
import
Enum
from
datetime
import
datetime
class
MixinHasValue
:
_value2member_map_
=
None
@classmethod
def
has_value
(
cls
,
value
)
->
bool
:
"""
check value in Enum
example: ExampleEnum.has_value(
"
test-string
"
)
"""
return
value
in
cls
.
_value2member_map_
class
ChainTypes
(
MixinHasValue
,
str
,
Enum
):
esbocs
=
"
esbocs
"
dag_poa
=
"
dag_poa
"
class
DatumTypes
(
MixinHasValue
,
str
,
Enum
):
DATUM_TX
=
"
DATUM_TX
"
DATUM_TOKEN_DECL
=
"
DATUM_TOKEN_DECL
"
DATUM_TOKEN_EMISSION
=
"
DATUM_TOKEN_EMISSION
"
DATUM_CUSTOM
=
"
DATUM_CUSTOM
"
DATUM_DECREE
=
"
DATUM_DECREE
"
DATUM_ANCHOR
=
"
DATUM_ANCHOR
"
class
AtomTypes
(
MixinHasValue
,
str
,
Enum
):
EVENT
=
"
EVENT
"
BLOCK
=
"
BLOCK
"
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
register
or
sign in
to comment