consensus/cmd/web/views/funcs.qtpl

168 lines
4.8 KiB
Plaintext

{% import "git.gammaspectra.live/P2Pool/p2pool-observer/types" %}
{% import "git.gammaspectra.live/P2Pool/p2pool-observer/monero/crypto" %}
{% import "git.gammaspectra.live/P2Pool/p2pool-observer/utils" %}
{% import "git.gammaspectra.live/P2Pool/p2pool-observer/p2pool/sidechain" %}
{% import "git.gammaspectra.live/P2Pool/p2pool-observer/cmd/index" %}
{% import p2pooltypes "git.gammaspectra.live/P2Pool/p2pool-observer/p2pool/types" %}
{% import "encoding/binary" %}
{% import "fmt" %}
{% import "slices" %}
{% import hex2 "encoding/hex" %}
{% import fasthex "github.com/tmthrgd/go-hex" %}
{% stripspace %}
{% func hex(ctx *GlobalRequestContext, val any) %}
{% switch s := val.(type) %}
{% case string %}
{%s s %}
{% case types.Difficulty %}
{% code
fasthex.Encode(ctx.HexBuffer[:types.DifficultySize*2], s.Bytes())
%}
{%z= ctx.HexBuffer[:types.DifficultySize*2] %}
{% case crypto.PrivateKeyBytes %}
{% code
fasthex.Encode(ctx.HexBuffer[:], s[:])
%}
{%z= ctx.HexBuffer[:] %}
{% case crypto.PublicKeyBytes %}
{% code
fasthex.Encode(ctx.HexBuffer[:], s[:])
%}
{%z= ctx.HexBuffer[:] %}
{% case crypto.PrivateKey %}
{% code
fasthex.Encode(ctx.HexBuffer[:], s.AsSlice())
%}
{%z= ctx.HexBuffer[:] %}
{% case crypto.PublicKey %}
{% code
fasthex.Encode(ctx.HexBuffer[:], s.AsSlice())
%}
{%z= ctx.HexBuffer[:] %}
{% case types.Hash %}
{% code
fasthex.Encode(ctx.HexBuffer[:], s[:])
%}
{%z= ctx.HexBuffer[:] %}
{% case []byte %}
{%s= hex2.EncodeToString(s) %}
{% case uint32 %}
{% code
var buf [4]byte
binary.LittleEndian.PutUint32(buf[:], s)
fasthex.Encode(ctx.HexBuffer[:4*2], buf[:])
%}
{%z= ctx.HexBuffer[:4*2] %}
{% case uint64 %}
{% code
var buf [8]byte
binary.LittleEndian.PutUint64(buf[:], s)
fasthex.Encode(ctx.HexBuffer[:8*2], buf[:])
%}
{%z= ctx.HexBuffer[:8*2] %}
{% default %}
{%v val %}
{% endswitch %}
{% endfunc %}
{% func shorten(ctx *GlobalRequestContext, val any, n int) %}
{% switch s := val.(type) %}
{% case string %}
{%s utils.Shorten(s, n) %}
{% case []byte %}
{%z= utils.ShortenSlice(slices.Clone(s), n) %}
{% case crypto.PrivateKeyBytes %}
{% code
fasthex.Encode(ctx.HexBuffer[:], s[:])
%}
{%z= utils.ShortenSlice(ctx.HexBuffer[:], n) %}
{% case crypto.PublicKeyBytes %}
{% code
fasthex.Encode(ctx.HexBuffer[:], s[:])
%}
{%z= utils.ShortenSlice(ctx.HexBuffer[:], n) %}
{% case crypto.PrivateKey %}
{% code
fasthex.Encode(ctx.HexBuffer[:], s.AsSlice())
%}
{%z= utils.ShortenSlice(ctx.HexBuffer[:], n) %}
{% case crypto.PublicKey %}
{% code
fasthex.Encode(ctx.HexBuffer[:], s.AsSlice())
%}
{%z= utils.ShortenSlice(ctx.HexBuffer[:], n) %}
{% case types.Hash %}
{% code
fasthex.Encode(ctx.HexBuffer[:], s[:])
%}
{%z= utils.ShortenSlice(ctx.HexBuffer[:], n) %}
{% case fmt.Stringer %}
{%s utils.Shorten(s.String(), n) %}
{% default %}
{%s utils.Shorten(fmt.Sprintf("%v", val), n) %}
{% endswitch %}
{% endfunc %}
{% func henc(val any) %}
{% code
var buf [types.HashSize*2+1]byte
%}
{% switch s := val.(type) %}
{% case types.Hash %}
{% code
dst := utils.EncodeSliceBinaryNumber(buf[:], s[:])
%}
{%z= dst[:] %}
{% case crypto.PrivateKeyBytes %}
{% code
dst := utils.EncodeSliceBinaryNumber(buf[:], s[:])
%}
{%z= dst[:] %}
{% case string %}
{%s= utils.EncodeHexBinaryNumber(s) %}
{% case fmt.Stringer %}
{%s= utils.EncodeHexBinaryNumber(s.String()) %}
{% default %}
panic("type not allowed")
{% endswitch %}
{% endfunc %}
{% func software_info(softwareId p2pooltypes.SoftwareId, softwareVersion p2pooltypes.SoftwareVersion) %}
{% if softwareId == 0 && softwareVersion == 0 %}
Not present
{% else %}
{%s= softwareId.String() %}{%s= ` ` %}{%s= softwareVersion.String() %}
{% endif %}
{% endfunc %}
{% func side_block_valuation(b any, consensus *sidechain.Consensus) %}
{% switch block := b.(type) %}
{% case *index.SideBlock %}
{% if block.IsOrphan() %}
0%
{% elseif block.IsUncle() %}
{%dul 100-consensus.UnclePenalty %}%{%s= ` ` %}(uncle)
{% elseif len(block.Uncles) > 0 %}
100%{%s= ` ` %}+{%s= ` ` %}{%dul consensus.UnclePenalty %}%{%s= ` ` %}of{%s= ` ` %}{%d len(block.Uncles) %}{%s= ` ` %}uncle(s)
{% else %}
100%
{% endif %}
{% case *sidechain.PoolBlock %}
{% if len(block.Side.Uncles) > 0 %}
100%{%s= ` ` %}+{%s= ` ` %}{%dul consensus.UnclePenalty %}%{%s= ` ` %}of{%s= ` ` %}{%d len(block.Side.Uncles) %}{%s= ` ` %}uncle(s)
{% else %}
100%
{% endif %}
{% default %}
panic("type not allowed")
{% endswitch %}
{% endfunc %}
{% endstripspace %}