FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bitcore/SIN.js at master · FrictionlessCoin/bitcore · GitHub
FrictionlessCoin
bitcore
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
bitcore
/
SIN.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
55 lines (49 loc) · 1.6 KB
Breadcrumbs
bitcore
/
SIN.js
Copy path
File metadata and controls
55 lines (49 loc) · 1.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
var
imports
=
require
(
'soop'
)
.
imports
(
)
;
var
parent
=
imports
.
parent
||
require
(
'./util/VersionedData'
)
;
function
SIN
(
type
,
payload
)
{
if
(
typeof
type
!=
'number'
)
{
SIN
.
super
(
this
,
arguments
)
;
return
;
}
;
this
.
data
=
new
Buffer
(
1
+
1
+
payload
.
length
)
;
this
.
__proto__
=
this
.
encodings
[
'binary'
]
;
this
.
prefix
(
0x0F
)
;
// SIN magic number, in numberspace
this
.
type
(
type
)
;
this
.
payload
(
payload
)
;
}
;
SIN
.
parent
=
parent
;
parent
.
applyEncodingsTo
(
SIN
)
;
SIN
.
SIN_PERSIST_MAINNET
=
0x01
;
// associated with sacrifice TX
SIN
.
SIN_PERSIST_TESTNET
=
0x11
;
// associated with sacrifice TX
SIN
.
SIN_EPHEM
=
0x02
;
// generate off-net at any time
// get or set the prefix data (the first byte of the address)
SIN
.
prototype
.
prefix
=
function
(
num
)
{
if
(
num
||
(
num
===
0
)
)
{
this
.
doAsBinary
(
function
(
)
{
this
.
data
.
writeUInt8
(
num
,
0
)
;
}
)
;
return
num
;
}
return
this
.
as
(
'binary'
)
.
readUInt8
(
0
)
;
}
;
// get or set the SIN-type data (the second byte of the address)
SIN
.
prototype
.
type
=
function
(
num
)
{
if
(
num
||
(
num
===
0
)
)
{
this
.
doAsBinary
(
function
(
)
{
this
.
data
.
writeUInt8
(
num
,
1
)
;
}
)
;
return
num
;
}
return
this
.
as
(
'binary'
)
.
readUInt8
(
1
)
;
}
;
// get or set the payload data (as a Buffer object)
SIN
.
prototype
.
payload
=
function
(
data
)
{
if
(
data
)
{
this
.
doAsBinary
(
function
(
)
{
data
.
copy
(
this
.
data
,
2
)
;
}
)
;
return
data
;
}
return
this
.
as
(
'binary'
)
.
slice
(
1
)
;
}
;
SIN
.
prototype
.
validate
=
function
(
)
{
this
.
doAsBinary
(
function
(
)
{
SIN
.
super
(
this
,
'validate'
,
arguments
)
;
if
(
this
.
data
.
length
!=
22
)
throw
new
Error
(
'invalid data length'
)
;
}
)
;
}
;
module
.
exports
=
require
(
'soop'
)
(
SIN
)
;
Back
|
FazBrowse Home
|
New Git URL