GithubHelp home page GithubHelp logo

oneblockplus-homecourse5's Introduction

oneblockplus-course-task5

不是完整的项目,仅上传关键代码

问题5: 实现存证模块的功能,包括:创建存证;撤销存证。

  1. 代码(详见 poe/src/lib.rs):
 #[pallet::weight(0)]
        pub fn create_claim(
            origin: OriginFor<T>,
            claim: Vec<u8>
        ) -> DispatchResultWithPostInfo {
            let sender = ensure_signed(origin)?;
            ensure!(!Proofs::<T>::contains_key(&claim), Error::<T>::ProofAlreadyExist);

            Proofs::<T>::insert(
                &claim,
                (sender.clone(),frame_system::Pallet::<T>::block_number())
            );

            Self::deposit_event(Event::ClaimCreated(sender, claim));

            Ok(().into())

        }

        #[pallet::weight(0)]
        pub fn revoke_claim(
            origin: OriginFor<T>,
            claim: Vec<u8>
        ) -> DispatchResultWithPostInfo {
            let sender = ensure_signed(origin)?;
            let (owner, _) = Proofs::<T>::get(&claim).ok_or(Error::<T>::ClaimNotExist)?;
            ensure!(owner == sender, Error::<T>::NotClaimOwner);

            Proofs::<T>::remove(&claim);

            Self::deposit_event(Event::ClaimRevoked(sender, claim));
            Ok(().into())
        }
  1. 运行的截图:

1-1

1-2

1-3

1-4

问题5:为存证模块添加新的功能,转移存证,接收两个参数,一个是内容的哈希值,另一个是存证的接收账户地址。

  1. 代码(详见 poe/lib.rs):
       #[pallet::weight(0)]
        pub fn translate_claim(
            dest: OriginFor<T>,
            claim: Vec<u8>
        ) -> DispatchResultWithPostInfo {
            let receiver = ensure_signed(dest)?;
            let (_, _) = Proofs::<T>::get(&claim).ok_or(Error::<T>::ClaimNotExist)?;

            Proofs::<T>::mutate(&claim, |d| match d {
                Some(data) => *data = (receiver.clone(),frame_system::Pallet::<T>::block_number()),
                _ => (),
            });

            Self::deposit_event(Event::ClaimTraslated(receiver, claim));
            Ok(().into())
        }
  1. 运行的截图: 2

2-2

oneblockplus-homecourse5's People

Contributors

songhaoxin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.