-
Notifications
You must be signed in to change notification settings - Fork 4
/
extra.go
39 lines (31 loc) 路 1.03 KB
/
extra.go
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
package types
import (
"bytes"
sc "github.com/LimeChain/goscale"
)
// SignedExtra implements SignedExtension
// Extra data, E, is a tuple containing additional metadata about the extrinsic and the system it is meant to be executed in.
type SignedExtra struct {
Era Era
// a compact integer containing the nonce of the sender.
// The nonce must be incremented by one for each extrinsic created,
// otherwise the Polkadot network will reject the extrinsic.
Nonce sc.U32 // encode as Compact
// a compact integer containing the transactor pay including tip.
Fee sc.U128 // encode as Compact
}
func (e SignedExtra) Encode(buffer *bytes.Buffer) {
e.Era.Encode(buffer)
sc.ToCompact(e.Nonce).Encode(buffer)
sc.Compact(e.Fee).Encode(buffer)
}
func DecodeExtra(buffer *bytes.Buffer) SignedExtra {
e := SignedExtra{}
e.Era = DecodeEra(buffer)
e.Nonce = sc.U32(sc.U128(sc.DecodeCompact(buffer)).ToBigInt().Uint64())
e.Fee = sc.U128(sc.DecodeCompact(buffer))
return e
}
func (e SignedExtra) Bytes() []byte {
return sc.EncodedBytes(e)
}