Skip to content
Snippets Groups Projects
  • Ching-Hua (Vivian) Lin's avatar
    a15f2729
    feat: Implement faucet dApp (#531) · a15f2729
    Ching-Hua (Vivian) Lin authored
    * Feat: Integrate faucet page to SPA plugin
    
    * Feat: Add Link to get txn of issued address
    
    * Feat: Add faucet payload
    
    * Feat: Add faucet plugin and minor tweaks
    
    * Fix: Check payload type after the txn is solid
    
    * Fix: Update package name
    
    * Fix: Fix payload test
    
    * Test: Add faucet test
    
    * Refactor: Minor tweaks in plugin/faucet.go
    
    * Feat: Add faucet webapi
    
    * Feat: Apply faucet plugins
    
    * Feat: Apply messagefactory and update to latest develop
    
    * Fix: Fix import error
    
    * Fix: Fix tests in binary/faucet
    
    * Feat: Integrate faucet page to SPA plugin
    
    * Feat: Add Link to get txn of issued address
    
    * Feat: Add faucet payload
    
    * Feat: Add faucet plugin and minor tweaks
    
    * Fix: Check payload type after the txn is solid
    
    * Fix: Update package name
    
    * Fix: Fix payload test
    
    * Test: Add faucet test
    
    * Refactor: Minor tweaks in plugin/faucet.go
    
    * Feat: Add faucet webapi
    
    * Feat: Apply faucet plugins
    
    * Feat: Apply messagefactory and update to latest develop
    
    * Fix: Fix import error
    
    * Fix: Fix tests in binary/faucet
    
    * refactor: Update to latest usage
    
    * fix: Update go.mod, go.sum
    
    * refactor: Disable faucet plugin by default
    
    * fix: Update to latest changes
    
    * feat: Add faucet payload layout
    
    * refactor: Move faucet to dapps
    
    * feat: Enable the faucet to send funds :sparkles:
    
    * Fix: fix tests
    
    * fix: Fix test
    
    * fix: Initiate LedgerState
    
    * Update packr on dashboard
    
    * refactor: refactor SendFunds in faucet dapp
    
    * feat: Add faucet integration test
    
    * feat: Add faucet integration test to script
    
    * doc: Add function descriptions
    
    * fix: fix wrong parameter in CheckBalances
    
    * fix: fix :dog:
    
    * fix some stuff
    
    * make the faucet configurable via CLI flags
    
    * make the faucet seed a parameter in the integration tests
    
    * activate the faucet on the peer master in docker-network
    
    * fixes wrong address route in faucet view
    
    * improves faucet processing log message
    
    * fix log messages in faucet dapp
    
    * improve error message further
    
    * fixes unit tests
    
    * adds tool to auto. gen. address
    
    * dog
    
    * wait for faucet funding tx to get booked before processing the next request
    
    * make the dog stay silent
    
    * decrease pow difficulty to 1 in int. tests
    
    * use 4 as the pow difficulty in integration tests
    
    * :dog:
    
    
    
    * fix integration tests
    
    * dec. pow diff to 1
    
    * use 0 for the faucet integration test
    
    * use a worker pool to serve faucet funding requests
    
    Co-authored-by: default avatarLuca Moser <moser.luca@gmail.com>
    feat: Implement faucet dApp (#531)
    Ching-Hua (Vivian) Lin authored
    * Feat: Integrate faucet page to SPA plugin
    
    * Feat: Add Link to get txn of issued address
    
    * Feat: Add faucet payload
    
    * Feat: Add faucet plugin and minor tweaks
    
    * Fix: Check payload type after the txn is solid
    
    * Fix: Update package name
    
    * Fix: Fix payload test
    
    * Test: Add faucet test
    
    * Refactor: Minor tweaks in plugin/faucet.go
    
    * Feat: Add faucet webapi
    
    * Feat: Apply faucet plugins
    
    * Feat: Apply messagefactory and update to latest develop
    
    * Fix: Fix import error
    
    * Fix: Fix tests in binary/faucet
    
    * Feat: Integrate faucet page to SPA plugin
    
    * Feat: Add Link to get txn of issued address
    
    * Feat: Add faucet payload
    
    * Feat: Add faucet plugin and minor tweaks
    
    * Fix: Check payload type after the txn is solid
    
    * Fix: Update package name
    
    * Fix: Fix payload test
    
    * Test: Add faucet test
    
    * Refactor: Minor tweaks in plugin/faucet.go
    
    * Feat: Add faucet webapi
    
    * Feat: Apply faucet plugins
    
    * Feat: Apply messagefactory and update to latest develop
    
    * Fix: Fix import error
    
    * Fix: Fix tests in binary/faucet
    
    * refactor: Update to latest usage
    
    * fix: Update go.mod, go.sum
    
    * refactor: Disable faucet plugin by default
    
    * fix: Update to latest changes
    
    * feat: Add faucet payload layout
    
    * refactor: Move faucet to dapps
    
    * feat: Enable the faucet to send funds :sparkles:
    
    * Fix: fix tests
    
    * fix: Fix test
    
    * fix: Initiate LedgerState
    
    * Update packr on dashboard
    
    * refactor: refactor SendFunds in faucet dapp
    
    * feat: Add faucet integration test
    
    * feat: Add faucet integration test to script
    
    * doc: Add function descriptions
    
    * fix: fix wrong parameter in CheckBalances
    
    * fix: fix :dog:
    
    * fix some stuff
    
    * make the faucet configurable via CLI flags
    
    * make the faucet seed a parameter in the integration tests
    
    * activate the faucet on the peer master in docker-network
    
    * fixes wrong address route in faucet view
    
    * improves faucet processing log message
    
    * fix log messages in faucet dapp
    
    * improve error message further
    
    * fixes unit tests
    
    * adds tool to auto. gen. address
    
    * dog
    
    * wait for faucet funding tx to get booked before processing the next request
    
    * make the dog stay silent
    
    * decrease pow difficulty to 1 in int. tests
    
    * use 4 as the pow difficulty in integration tests
    
    * :dog:
    
    
    
    * fix integration tests
    
    * dec. pow diff to 1
    
    * use 0 for the faucet integration test
    
    * use a worker pool to serve faucet funding requests
    
    Co-authored-by: default avatarLuca Moser <moser.luca@gmail.com>
payload.go 3.42 KiB
package faucetpayload

import (
	"github.com/iotaledger/goshimmer/packages/binary/messagelayer/message"
	"github.com/iotaledger/hive.go/marshalutil"
	"github.com/iotaledger/hive.go/stringify"

	"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address"
	"github.com/iotaledger/goshimmer/packages/binary/messagelayer/payload"
)

// Payload represents a request which contains an address for the faucet to send funds to.
type Payload struct {
	payloadType payload.Type
	address     address.Address
}

// Type represents the identifier for the faucet Payload type.
var Type = payload.Type(2)

// New is the constructor of a Payload and creates a new Payload object from the given details.
func New(addr address.Address) *Payload {
	return &Payload{
		payloadType: Type,
		address:     addr,
	}
}

func init() {
	payload.RegisterType(Type, GenericPayloadUnmarshalerFactory(Type))
}

// FromBytes parses the marshaled version of a Payload into an object.
// It either returns a new Payload or fills an optionally provided Payload with the parsed information.
func FromBytes(bytes []byte, optionalTargetObject ...*Payload) (result *Payload, err error, consumedBytes int) {
	// determine the target object that will hold the unmarshaled information
	switch len(optionalTargetObject) {
	case 0:
		result = &Payload{}
	case 1:
		result = optionalTargetObject[0]
	default:
		panic("too many arguments in call to FromBytes")
	}

	// initialize helper
	marshalUtil := marshalutil.New(bytes)

	// read data
	result.payloadType, err = marshalUtil.ReadUint32()
	if err != nil {
		return
	}
	payloadBytes, err := marshalUtil.ReadUint32()
	if err != nil {
		return
	}
	addr, err := marshalUtil.ReadBytes(int(payloadBytes))
	if err != nil {
		return
	}
	result.address, _, _ = address.FromBytes(addr)

	// return the number of bytes we processed
	consumedBytes = marshalUtil.ReadOffset()

	return
}

// Type returns the type of the faucet Payload.
func (faucetPayload *Payload) Type() payload.Type {
	return faucetPayload.payloadType
}

// Address returns the address of the faucet Payload.
func (faucetPayload *Payload) Address() address.Address {
	return faucetPayload.address
}

// Bytes marshals the data payload into a sequence of bytes.
func (faucetPayload *Payload) Bytes() []byte {
	// initialize helper
	marshalUtil := marshalutil.New()

	// marshal the payload specific information
	marshalUtil.WriteUint32(faucetPayload.Type())
	marshalUtil.WriteUint32(uint32(len(faucetPayload.address)))
	marshalUtil.WriteBytes(faucetPayload.address.Bytes())

	// return result
	return marshalUtil.Bytes()
}

// Unmarshal unmarshals a given slice of bytes and fills the object.
func (faucetPayload *Payload) Unmarshal(data []byte) (err error) {
	_, err, _ = FromBytes(data, faucetPayload)

	return
}

// String returns a human readable version of faucet payload (for debug purposes).
func (faucetPayload *Payload) String() string {
	return stringify.Struct("FaucetPayload",
		stringify.StructField("address", faucetPayload.Address().String()),
	)
}

// GenericPayloadUnmarshalerFactory sets the generic unmarshaler.
func GenericPayloadUnmarshalerFactory(payloadType payload.Type) payload.Unmarshaler {
	return func(data []byte) (payload payload.Payload, err error) {
		payload = &Payload{
			payloadType: payloadType,
		}
		err = payload.Unmarshal(data)

		return
	}
}

// IsFaucetReq checks if the message is faucet payload.
func IsFaucetReq(msg *message.Message) bool {
	return msg.Payload().Type() == Type
}