-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.txt
139 lines (94 loc) · 4.46 KB
/
notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
Blockchain
Distributed data storage across many machines-> collection of containers (blocks) which are connected. Order of blocks matter.
Each block contains some data (much like an individual folder). Each block knows about what came before it.
Subfolders within blockchain is what is contained within block. Runs on multiple nodes (wallet)
A block can contain any type of data.
Multiple blocks exist in one blockchain. Each block knows about the other (a hash/unique id. Same txt for
same input). The following block has this data from the preceding block.
Therefore, same input = same output. No other input leads to same hash
Cryptocurrency
Data you store in a block is a list of transactions, the coins transferred in the form of your Cryptocurrency
3 Core concepts: **WHO IS SENDING HOW MUCH TO WHOM**
Coins are transferred with transactions. Cant' be changed to other real currencies inside the blockchain.
Value of coin determined by the value the participants of the blockchain assign to it. What is willing
to be paid for it in a real currency. (USD, EU).
Therefore, high volatility.
Coins created by mining ( a reward for the effort ) -> how new blocks are added, via new transactions. Adding
a new block to the blockchain.
Distributed, secure data storage. Cryptocurrency is if the content is coins that are sent a to b
2. Diving into PY
REPL -> RedEvalPrintLoop
R 2+2
E ...
P 4
Loop --> back to start
DATA TYPES
Number -> INTEGER (34) and FLOAT (1.8679)
Booleans -> True/False
Strings -> Text (' or ")
ctrl + z to exit PY REPL
Integer -> can hold as big or small a number as supported by OS
int() converts value to an integer (how to avoid string concat)
Float always rounds down!
Float -> can hold as big or small a number as supported by OS
float() converts value to a float (how to avoid string concat)\
Integers and floats can be written with underscores as a means to conveniently format them, make themm
more readable! 1_000_000
Operators
/ Division always results in a FLOAT
// is integer division that returns an integer, removing decimal place
** power of Operators
% modulus returns the remainder
*Multiply strings! Repeats the string the number of times specified
Ex. "Hello" * 5 = HelloHelloHelloHelloHello
Exponential notation: 1e5 (typically stores as a float)
Floating point imprecision is the result of values that are not cleanly divisible,
hence values like 1 - 0.9 does not output 0.01 BUT 0.0999999999.
Inherent to computers and python
Strings
'' or ""
"" allow you to use ' within them, without having to escape chars
To write longer text with line breaks:
long_text = """you can add your test\n more text"""
Lists (read ARRAY)
Can hold multiple values of same type, or of multiple types
[ , , , , ]
access value stored at an index: blockchain[2]
List is unchainged if you referece data in an index and modify it
List methods .append(valueToAdd)
.pop() - removes last value of list (returning the removed value)
Fuctions
def functionName():
return Value
default args defined within paren as (varName = 4)
If arg not provided, this default value used
Two lines between function definitions are part of official style for PY
Keyword arguments allow us to pass arguments different from the order in which they are defined
What data should go into which arg
arg_name=value arg_nae2=value
Variable Scope
Global -> Root level definition (not in a function)
Local -> A variable defined within a function
use global keyword before a variable to use global version of a variable
**Check PEP Docs for style guide, proposals for Python spec, etc!**
PEP 8 for styling
DOCSTRINGS, multi-line strings """ """
This adds an explanation or string data to a function
def function_name(args)
"""Summary of the function
Arguments:
:trans_amount
"""
Proof Of Work (PoW)
-Increases challenge of mining blocks (more time and resources)
-Controls speed by which coins enter our network
-Essential security concept that prevents editing blockchain
==
Employs using a hash that takes some block data (trans + prev_hash)
to fulfill some criteria to validate the work. Added to block metadata.
Other nodes can easily verify the proof of work and hence the validity of the block.
==
-Generate hash from: transactions, previous hash, proof number (nonce - num used once)
-64 Characters (if using SHA256)
-Beginning characters have a set of leading characters, typically X 0s. The more 0s, the
harder the computation.