misskey-dev / misskey

🌎 An interplanetary microblogging platform 🚀
https://misskey-hub.net/
GNU Affero General Public License v3.0
9.84k stars 1.33k forks source link

ノートに対する投げ銭機能 #6653

Open tamaina opened 4 years ago

tamaina commented 4 years ago

Summary

私は日々「Misskeyを収益化する」ことを漠然と考えているのですが、その一案として、「ノートに対して記事購読料を払う」という感じで、ノートに対して購読料を払う(投げ銭をする)機能が実装できたらお金の動きができるのではないかと思っています。

特定のサービスに頼るのはどうかと思うので、ETHとMetaMaskを用いるのがいいのかなと。

※ Misskeyのバックエンドに暗号通過の秘密鍵を送信するようなシステムは本人認証が必要だが、公開鍵やアドレスを保存するには当然問題ないはず

Ideas

tamaina commented 3 years ago

メモ: Contract

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

contract MisskeyInstancePayment {
    address owner;

    constructor() payable {
        owner = msg.sender;
    }

    function local(address payable addr) public payable {
        uint256 fee = msg.value / 10;
        addr.transfer(msg.value - fee);
    }

    function toRemote(address payable addr, MisskeyInstancePayment remoteAddr) public payable {
        if (remoteAddr == this) {
            this.local(addr);
        } else {
            uint256 fee = msg.value / 10;
            remoteAddr.fromRemote{ value: (msg.value - fee) }(addr, msg.value, fee);
        }
    }

    function fromRemote(address payable addr, uint256 input, uint256 remoteFee) public payable {
        uint256 fee = input / 20;
        addr.transfer(input - fee - remoteFee);
    }

    function payout() public payable {
        require(msg.sender == owner);
        payable(msg.sender).transfer(address(this).balance);
    }
}
tamaina commented 3 years ago

実際にはfeeの割合を設定できるようにするのと、イベントを発行する必要がありそう

Contractで多少節約にはなるけど600円~800円とかかかるのでやはり使い物にならない(gasが30k~40k、レートが200kJPY/ETH、gas priceが100Gweiとして)

Ethereum2.0は解決されているらしいので期待

syuilo commented 3 years ago

開発が進んでいる https://twitter.com/gitmolife/status/1385290071666880513?s=21

defango commented 3 years ago

I didn't notice people were working on this. We forked Misskey and have been working on getting crypto inside. We are testing with OHMCoin but our system will allow for as many coins as. you like. So far we have wallets getting created for users and the ability to tip on notes. If its a renote the tip goes to the OG poster. Right now we have not really changed misskey proper, we are trying to just make it like a plugin but currently it needs the fork. We have a testing site up were you can make an account and check things out.

Github Diff https://github.com/gitmolife/gitmo/pull/11

Testing site https://test.ohmc.tips/

tamaina commented 3 years ago

まじかよ

(コード読んでみたけど、PoSの実際の実装をまだ理解できていないので、Intercom2の動作とかがあんまりわかってない

defango commented 3 years ago

its kinda simple. We have a wallet wrapper over the Ohmcoin (PoS) wallet installed on the server. The Master Misskey worker makes IPC calls to the Intercom Broker Worker locally to make things happen with the wallet. The wallet Wrapper is a Separate Daemon for the misskey master worker. If someone makes an action with tipping it forwards it to the master worker then triggers wallet wrapper to start the crypto trade function. Then the Intercom broker takes care of syncing with the Master worker and making the database updates.

This allows us to keep the worker size down by not having a intercom broker on every worker. This will help if anyone decides to place misskey workers on crypto networks or places like Cloudflare. So all the posting and things can be done with no limits or slowdown and when tipping happens it routes to the main worker.

The intercom Broker is sitting over the top of the wallet works as messaging system between the wallet, chain and misskey. It allows the records to be read and updated. It basically keeps the Chain wallet and Database updated. Every 4 minutes it scans the blockchain for new records to keep it up today.

its Important because it allows us to run on the same server as misskey without having to major changes to the overall system. We are just adding some libs and things to the project like we did with the video.js implementation. That way it can be added or not added to misskey instances and keep fully in line with your overall code structure.

There are basically 2 methods people use for Crypto to websites. We are mixing the 2 methods. Inter misskey tips are off chain but deposits and withdrawls are on chain. This will let us use any crypto we would like.

Method 1: Fractional Reserve System

Pros:

Cons:

Pros:

Cons:

Method 2: On Chain Backed System

Pros:

Cons:

We are doing a test on test.ohm.tips then will be going live on gitmo.life

Right now we aren't allowing people to tip remote instances but its something we can probably figure out with your help.

It would be impossible expensive to go on chain with eth based on Price and Gas fees alone. It would really slow the down site having to put. Something like Cosmos network would be more helpful in a lot of ways but is still pricey. With this we could allow for eth wallets that people can tip out of and still allow them to withdrawl but they would have to pay fees. This Intercom system was made for Bitcoin but will work with just about any crypto on the market right now.

This is just the start for getting Web3 on the system. So people can use metamask to sign in with their wallet

tamaina commented 3 years ago

サーバーが送金を代行できる形でウォレットを管理する("custody")のは、日本だと暗号資産交換業となっていろいろな法規制が発生するので、日本では使うのは簡単ではないのです。日本で使うならMethod 2しか選択肢がない。

defango commented 3 years ago

I have looked into the Japan/US regulations and we have setup the system in a way that falls in line with their laws. Since we are using a mixture of method 1 and 2 we actually made sure to keep this in mind for you guys when doing this. To be considered a "Crypto Asset Exchange service" you have to fall into a couple of lines. I'll explain to the best of my ability.

https://www.globallegalinsights.com/practice-areas/blockchain-laws-and-regulations/japan

The term “Crypto Asset” is defined in the PSA as:

proprietary value that may be used to pay an unspecified person the price of any goods purchased or borrowed or any services provided and which may be sold to or purchased from an unspecified person (limited to that recorded on electronic devices or other objects by electronic means and excluding Japanese and other foreign currencies and Currency Denominated Assets; the same applies in the following item) and that may be transferred using an electronic data processing system; or

a. Sale or Purchase of Crypto Asset, or the exchange of a crypto asset;

You have to be selling, buying or trading crypto assets for FIAT or different assets. 2 things we to no offer in any way. users are only able to send and receive the same type of currency and have no options to exchange or trade for any other asset. This is something that is similar in the US and we didn't wanna worry abou that.

b. intermediating, broker or acting as an agent inrespect to the activities listed in item (a);

We don't fall in this area since we aren't brokering transactions or transfers in respect to sale, purchase, or exchange. We are just offering a wallet application interface.

c. Management of customers money in connection with activities listed in item (a) and (b);

Since we aren't doing anything in A or B we aren't considered to be in the management of customers money since we only offer a wallet application interface for people to use to send the same crypto between the same type of wallet.

d. Management of customers' crypto assets for the benefit of another person.

Since we are only providing users with a crypto asset wallet application (Non-custodial wallet) and private keys our implementation does not constitute a crypto asset custody service.

Since we are generating wallets for the users to interface with the website and giving them the control over custody of the wallet we are outside of the regulations on these types of systems, We kept that in mind when rolling this out with our mixed method. All deposits and withdrawals are on chain transactions initiated by the user and they are in full control of the assets. when they transfer to the tipping wallet it's still being managed by the end user as a wallet control system for protecting assets enabled by the user. So the main wallet is using Method 2 and when a user transfers assets to tip on the site it moves into a method 1 wallet attached to the method 2 wallet. When a user transfers their tipping wallet balance back to their method 2 wallet its fully managed by the user via the private keys they have access to. When a tip is made the transaction is staged with other tips and run on the blockchain when a few tips have been collected and sent as a 1 single multi output transaction settling the tipping wallet balances with the On chain network and keeping track of the microtransactions.

The key here is the non custodial nature of the implementation

squidicuzz commented 3 years ago

まじかよ

(コード読んでみたけど、PoSの実際の実装をまだ理解できていないので、Intercom2の動作とかがあんまりわかってない

Intercom2 is just a messaging bus, basically. It basically facilitates communication between the wallet daemon (i.e. Bitcoin core, or something like Ohmcoin) and the website. The "Broker" is what handles calls from the site and processes them through the bus.

I will post more info and sources for Intercom2 soon..

As @defango explained some above. There are two ways to use this (Intercom2), and go about creating a crypto based wallet system. However, to do micro-transactions on chain is not entirely practical due to exponential growth of fees. So a hybrid system is used.
Every user registered in the system is given their own set of keys within the wallet. But to perform micro-transactions (i.e. Tips), they must move coins into their tipping account. Which is the point things get tricky I guess?

I don't believe this system would be classified as a "Crypto Asset Custody Service" since it is "Non-Custodial" in design. Ideally, it is possible for users to hold a copy of their private key from the site, and the site would also have the key and detect any usage of it.

I will do some research and elaborate more soon.

squidicuzz commented 3 years ago

Experimental Features - Update

We have merged https://github.com/gitmolife/gitmo/pull/11 and an experimental system implementation is live on @defango's instance gitmo.life as well as the test server posted, if anyone wants to try or check it out. Currently it uses a hybrid combination of methods 1 and 2 (noted above) to accomplish tips. The system will audit against the blockchain to assure balances are accurate with the db cache on the site.

There is ability to tip on notes, and it seems to work with the federation network fine so far. The tip option does not show on remote notes, or on notes that you have posted yourself. It will also show the amount tipped on/to the note, and turns orange if you have tipped that note.

The relevant source code for the crypto implementation into Misskey is currently located in a side-branch for review.

If there is interest and such crypto features desired in a more general form for other instances (and possibly coins), we can work on a more formal implementation of this system and put together a PR for upstream Misskey. This would include optional support for usage and customization of, with different modes of operation to accommodate various region(?) requirements.


Quick Overview

Intercom2 is a two-directional messaging bus which supports secure socket communication and allows for message payloads to be sent to and received by connected applications in the bus network.
In this case we are using it with a wallet RPC wrapper on a coin daemon, with a broker interface to the misskey app and site.

Below is an updated layout diagram of the current underlying major components that make up the instance. I clarified some labels. gitmo io_broker_ex2


We will be finalizing and putting together a release for Intercom2 repository and development usage documents soon.

If there is significant interest in inclusion of cryptocurrency into Misskey, I will work on putting a proper merge request for that as well. Please let me know.. :slightly_smiling_face:

silverpill commented 2 years ago

In case anyone is still interested in this, I've implemented subscriptions in my own project Mitra: https://codeberg.org/silverpill/mitra The server doesn't have control over the funds and subscription payment is made in a peer to peer fashion using a smart contract (the implementation is similar to "money streams" mechanism proposed in EIP-1620). This feature is compatible with other ActivityPub servers. Anyone can send payment and it will be detected automatically, the only requirement is that sender's profile should have an extra field containing ethereum wallet address. Subscribers-only posts are seen by other ActivityPub servers as direct messages (see this post for details: https://mitra.social/objects/01817db8-bc8f-1ccf-108c-83eed5a69af5).

tamaina commented 1 year ago

いらない

tamaina commented 7 months ago

リノートとリアクションだけでは表現できないくそでか感情をぶつけたいのでやりたい

KisaragiEffective commented 3 months ago

revisit: 特定商取引法関係が面倒そうなので外部プラットフォームに誘導するぐらいにしたい (個人的な意見)