Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 8c46686

Browse files
Merge pull request #70 from ava-labs/recent-activity
Recent activity
2 parents beadde8 + bd5a461 commit 8c46686

File tree

22 files changed

+472
-40
lines changed

22 files changed

+472
-40
lines changed

README.md

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Usage:
2222
spaces-cli [command]
2323
2424
Available Commands:
25+
activity View recent activity on the network
2526
claim Claims the given prefix
2627
completion generate the autocompletion script for the specified shell
2728
create Creates a new key in the default location
@@ -30,11 +31,13 @@ Available Commands:
3031
help Help about any command
3132
info Reads space info and all values at space
3233
lifeline Extends the life of a given prefix
34+
move Transfers a space to another address
3335
resolve Reads a value at space/key
3436
set Writes a key-value pair for the given prefix
37+
transfer Transfers units to another address
3538
3639
Flags:
37-
--endpoint string RPC Endpoint for VM (default "http://127.0.0.1:9650")
40+
--endpoint string RPC Endpoint for VM (default "https://memeshowdown.com")
3841
-h, --help help for spaces-cli
3942
--private-key-file string private key file path (default ".spaces-cli-pk")
4043
@@ -97,12 +100,12 @@ _Provide your intent and get back a transaction to sign._
97100

98101
#### Transaction Types
99102
```
100-
Claim {type,space}
101-
Lifeline {type,space,units}
102-
Set {type,space,key,value}
103-
Delete {type,space,key}
104-
Move {type,space,to}
105-
Transfer {type,to,units}
103+
claim {type,space}
104+
lifeline {type,space,units}
105+
set {type,space,key,value}
106+
delete {type,space,key}
107+
move {type,space,to}
108+
transfer {type,to,units}
106109
107110
```
108111

@@ -215,6 +218,32 @@ Transfer {type,to,units}
215218
>>> {"balance":<uint64>}
216219
```
217220

221+
## spacesvm.recentActivity
222+
```
223+
<<< POST
224+
{
225+
"jsonrpc": "2.0",
226+
"method": "spacesvm.recentActivity",
227+
"params":{},
228+
"id": 1
229+
}
230+
>>> {"activity":[<chain.Activity>,...]}
231+
```
232+
233+
### chain.Activity
234+
```
235+
{
236+
"timestamp":<unix>,
237+
"sender":<address>,
238+
"txId":<ID>,
239+
"type":<string>,
240+
"space":<string>,
241+
"key":<string>,
242+
"to":<hex encoded>,
243+
"units":<uint64>
244+
}
245+
```
246+
218247
# Advanced Public Endpoints (`/public`)
219248

220249
## spacesvm.suggestedRawFee
@@ -247,7 +276,7 @@ _Can use this to get the current fee rate._
247276
# Creating Transactions
248277
```
249278
1) spacesvm.claimed {"space":"patrick"} => Yes/No
250-
2) spacesvm.suggestedFee {"input":{"type":"Claim", "space":"patrick"}} => {"typedData":<EIP-712 Typed Data>, "cost":<total fee>}
279+
2) spacesvm.suggestedFee {"input":{"type":"claim", "space":"patrick"}} => {"typedData":<EIP-712 Typed Data>, "cost":<total fee>}
251280
3) sign EIP-712 Typed Data
252281
4) spacesvm.issueTx {"typedData":<from spacesvm.suggestedFee>, "signature":<sig from step 3>} => {"txId":<ID>}
253282
5) [loop] spacesvm.hasTx {"txId":<ID>} => {"accepted":true"}

chain/activity.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
package chain
5+
6+
import (
7+
"github.com/ava-labs/avalanchego/ids"
8+
)
9+
10+
type Activity struct {
11+
Tmstmp int64 `serialize:"true" json:"timestamp"`
12+
Sender string `serialize:"true" json:"sender"`
13+
TxID ids.ID `serialize:"true" json:"txId"`
14+
Typ string `serialize:"true" json:"type"`
15+
Space string `serialize:"true" json:"space,omitempty"`
16+
Key string `serialize:"true" json:"key,omitempty"`
17+
To string `serialize:"true" json:"to,omitempty"` // common.Address will be 0x000 when not populated
18+
Units uint64 `serialize:"true" json:"units,omitempty"`
19+
}

chain/claim_tx.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,10 @@ func (c *ClaimTx) TypedData() *tdata.TypedData {
110110
},
111111
)
112112
}
113+
114+
func (c *ClaimTx) Activity() *Activity {
115+
return &Activity{
116+
Typ: Claim,
117+
Space: c.Space,
118+
}
119+
}

chain/decoder.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import (
1515
)
1616

1717
const (
18-
Claim = "Claim"
19-
Lifeline = "Lifeline"
20-
Set = "Set"
21-
Delete = "Delete"
22-
Move = "Move"
23-
Transfer = "Transfer"
18+
Claim = "claim"
19+
Lifeline = "lifeline"
20+
Set = "set"
21+
Delete = "delete"
22+
Move = "move"
23+
Transfer = "transfer"
2424
)
2525

2626
type Input struct {

chain/delete_tx.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,11 @@ func (d *DeleteTx) TypedData() *tdata.TypedData {
8181
},
8282
)
8383
}
84+
85+
func (d *DeleteTx) Activity() *Activity {
86+
return &Activity{
87+
Typ: Delete,
88+
Space: d.Space,
89+
Key: d.Key,
90+
}
91+
}

chain/lifeline_tx.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,11 @@ func (l *LifelineTx) TypedData() *tdata.TypedData {
8484
},
8585
)
8686
}
87+
88+
func (l *LifelineTx) Activity() *Activity {
89+
return &Activity{
90+
Typ: Lifeline,
91+
Space: l.Space,
92+
Units: l.Units,
93+
}
94+
}

chain/move_tx.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,17 @@ func (m *MoveTx) TypedData() *tdata.TypedData {
7878
},
7979
tdata.TypedDataMessage{
8080
tdSpace: m.Space,
81-
tdTo: m.To,
81+
tdTo: m.To.Hex(),
8282
tdPrice: strconv.FormatUint(m.Price, 10),
8383
tdBlockID: m.BlockID.String(),
8484
},
8585
)
8686
}
87+
88+
func (m *MoveTx) Activity() *Activity {
89+
return &Activity{
90+
Typ: Move,
91+
Space: m.Space,
92+
To: m.To.Hex(),
93+
}
94+
}

chain/set_tx.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,11 @@ func (s *SetTx) TypedData() *tdata.TypedData {
122122
},
123123
)
124124
}
125+
126+
func (s *SetTx) Activity() *Activity {
127+
return &Activity{
128+
Typ: Set,
129+
Space: s.Space,
130+
Key: s.Key,
131+
}
132+
}

chain/transfer_tx.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,18 @@ func (t *TransferTx) TypedData() *tdata.TypedData {
6565
{Name: tdBlockID, Type: tdString},
6666
},
6767
tdata.TypedDataMessage{
68-
tdTo: t.To,
68+
tdTo: t.To.Hex(),
6969
tdUnits: strconv.FormatUint(t.Units, 10),
7070
tdPrice: strconv.FormatUint(t.Price, 10),
7171
tdBlockID: t.BlockID.String(),
7272
},
7373
)
7474
}
75+
76+
func (t *TransferTx) Activity() *Activity {
77+
return &Activity{
78+
Typ: Transfer,
79+
To: t.To.Hex(),
80+
Units: t.Units,
81+
}
82+
}

chain/tx.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,10 @@ func (t *Transaction) Execute(g *Genesis, db database.Database, blk *StatelessBl
136136
rewardAmount := t.FeeUnits(g) * blk.Price * g.LotteryRewardMultipler / g.LotteryRewardDivisor
137137
return ApplyReward(db, blk.ID(), t.ID(), t.sender, rewardAmount)
138138
}
139+
140+
func (t *Transaction) Activity() *Activity {
141+
activity := t.UnsignedTransaction.Activity()
142+
activity.Sender = t.sender.Hex()
143+
activity.TxID = t.id
144+
return activity
145+
}

0 commit comments

Comments
 (0)